1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aalyn [17]
2 years ago
6

Construct sequence using a specified number of integers within a range. The sequence must be strictly increasing at first and th

en strictly decreasing. The goal is to maximize the sequence array elements starting from the beginning. For example, [4, 5, 4, 3, 2] beats [3,4,5,4,3] because its first element is larger, and [4, 5, 6, 5, 4] beats [4,5,4,3,2] because its third element is larger. Given the length of the sequence and the range of integers, return the winning sequence. If it is not possible to construct such a sequence, return -1. Write an algorithm that returns a winning sequence and -1 if the sequence is not possible. Input The input to the function/method consists of three arguments: num : an integer representing the size of sequence to create lower End : an integer representing the lower end of integer range upperEnd : an integer representing the upper end of integer range.
Computers and Technology
1 answer:
natulia [17]2 years ago
7 0

Answer:

Explanation:

The following code is written in Java. It first creates a function that takes in the three parameters to create the sequence, if the sequence is valid it returns the created sequence, otherwise it prints -1 and returns an empty array. The second function called compareSequences takes in to sequences as parameters and compares them, printing out the winner. A test case has been provided in the main method and the output can be seen in the image below.

import java.util.Arrays;

class Brainly {

   public static void main(String[] args) {

       int[] seq1 = createSequence(5, 4, 2);

       int[] seq2 = createSequence(5, 3, 3);

       System.out.println("Winner: " + Arrays.toString(compareSequences(seq1, seq2)));

   }

   public static int[] createSequence(int num, int upperEnd, int lowerEnd) {

       int[] myArray = new int[num];

       int middle = (int) Math.floor(num/2.0);

       myArray[0] = upperEnd;

       myArray[num-1] = lowerEnd;

       int currentValue = upperEnd;

       for (int i = 1; i < num-1; i++) {

           if (i <= middle) {

               myArray[i] = currentValue + 1;

               currentValue += 1;

           } else {

               myArray[i] = currentValue - 1;

               currentValue += 1;

           }

       }

       System.out.println(Arrays.toString(myArray));

       if (myArray[num-2] < lowerEnd) {

           System.out.println("-1");

           int[] empty = {};

           return empty;

       } else {

           return myArray;

       }

   }

   public static int[] compareSequences(int[] seq1, int[] seq2) {

       int lowestLength;

       if (seq1.length > seq2.length) {

           lowestLength = seq2.length;

       } else {

           lowestLength = seq1.length;

       }

       for (int i = 0; i < lowestLength; i++) {

           if (seq1[i] > seq2[i]) {

               return seq1;

           } else if (seq1[i] < seq2[i]) {

               return seq2;

           }

       }

       if (seq1.length > seq2.length) {

           return seq1;

       } else {

           return seq2;

       }

   }

}

You might be interested in
6. Choose the TWO conditions that could be used for an IF-statement, without a compile-time error. Assume variable str is a Stri
KengaRu [80]

Answer:

  1. 4 ==5
  2. "six"== 6

Explanation:

3 0
3 years ago
Which reports indicate how traffic arrived at a website?.
tatyana61 [14]

Answer:

Direct traffics.

Explanation:

This channel refers to those traffics that came directly and without any via.

8 0
1 year ago
HOWARD!!!!!! THE PHONE IS RINGING!!!!!!!!!
777dan777 [17]

Answer:

i am confused

Explanation:

7 0
2 years ago
Read 2 more answers
Access-lists pose a logical problem which often has more than one solution. Can you think of a different set of rules or placeme
Maksim231197 [3]

Answer:

Question is incomplete. it needs a topology diagram and also it needs Router R1 table. I assume User has access to the topology and Routing table.

Below Configuration will help to fix ACL problem

Hosts from the 172.16.0.0/16 network should have full access to Server1, Server2 and Server3 but this is not currently the case, as L1 can’t communicate to Server2 or Server3.

Explanation:

Following Configuration on Cisco Router R1 will help to fix all the ACL problems.

enable

configure terminal

no ip access-list standard FROM_10

ip access-list standard FROM_10

deny host 10.0.0.2

permit any

exit

!

no ip access-list standard FROM_172

ip access-list standard FROM_172

permit host 172.16.0.2

exit

!

interface GigabitEthernet0/0

ip access-group FROM_192 out

end

write memory

!

7 0
3 years ago
Suppose the sender wants to send the following bit stream by using bit stuffing. What would the sender transmit if the following
Helen [10]

The purpose of bit stuffing is used as a delimiter to mark the end of one frame and the beginning of the next frame.

<h3>What is Bit Stuffing?</h3>

This refers to the use of one or more information bits in order to break up the message for easy synchronization.

The parts of a frame are:

  1. Frame header
  2. Payload field
  3. Trailer
  4. Flags.

<h3>What is a Flag?</h3>

This is a bit pattern that is used to define the start and end bits in a given frame and the 8-bit pattern 01111110 as the flag is commonly used.

Hence, we can see that your question is incomplete so I gave you a general overview to help you have a better understanding of the concept.


Read more about bit stuffing here:

brainly.com/question/12949292
#SPJ1

7 0
2 years ago
Other questions:
  • Reconstructing a noise deformed analog signal is an impossible task.
    6·1 answer
  • Why should you delete files from your computer? (multiple answers can be chosen)
    5·2 answers
  • Write any 2 differences between implicit variables and explicit variables.​Plz tell :' (
    10·1 answer
  • When studying an information system, illustrations of actual documents should be collected using a process called _____.
    12·1 answer
  • And there you go <br> sorry its saying my thing is tooo small
    14·2 answers
  • Which of the following TCP/IP settings should be configured to specify DNS suffixes to use other than resolving names through a
    9·1 answer
  • How many answers do you need to be able to write messages on here??
    6·1 answer
  • A new attack involves hacking into medical records and then offering these records for sale on the black market. A medical recor
    14·1 answer
  • What is cloud based LinkedIn Automation?
    12·2 answers
  • In python:
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!