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
AnnyKZ [126]
2 years ago
10

which one of the following will reach every element in the array a? 1. for(int i = 0; i <= a.length; i++) 2. for(int i = 0; i

< a.length; i++) 3. for(int i = 1; i <= a.length; i++) 4. for(int i= 1-1 ; i < a.length; i++)
Computers and Technology
1 answer:
andrey2020 [161]2 years ago
4 0

Answer:

You can simplify the problem down by recognizing that you just need to keep track of the integers you've seen in array that your given. You also need to account for edge cases for when the array is empty or the value you get would be greater than your max allowed value. Finally, you need to ensure O(n) complexity, you can't keep looping for every value you come across. This is where the boolean array comes in handy. See below -

public static int solution(int[] A)

{

int min = 1;

int max = 100000;

boolean[] vals = new boolean[max+1];

if(A.length == 0)

return min;

//mark the vals array with the integers we have seen in the A[]

for(int i = 0; i < A.length; i++)

{

if(A[i] < max + 1)

vals[A[i]] = true;

}

//start at our min val and loop until we come across a value we have not seen in A[]

for (int i = 1; i < max; i++)

{

if(vals[i] && min == i)

min++;

else if(!vals[i])

break;

}

if(min > max)

return max;

return min;

}

You might be interested in
Write an expression using a variable that shows how much 3 pairs of jeans will cost if you do not know the price of the jeans.as
stich3 [128]
Maybe y = 3 * x, that is my guess
8 0
4 years ago
Finish the program by choosing the correct terms.
juin [17]
What are the exact numbers
6 0
3 years ago
Read 2 more answers
How many different bit strings are there of length 6 that contain the string 0000?
Elena L [17]

Answer:

It can be 100001, 100000,000001,000000

Hence, answer is 4.

its also can be found through 2C2 *2 = 2!/0! *2 =2*2 =4

Explanation:

The answer is straight forward, we have 2 empty places and we can select from 2 items, and hence its 2C2, and now we can arrange them as well, and since we can arrange in 2 ways, hence a total number of possibility = 2 * 2C2 = 4, which is the required answer.

5 0
3 years ago
A slide in Blake's presentation contained the following information:
deff fn [24]

Answer:

consistent phrasing is missing

Explanation:

If you will note carefully, the bullets are not in correct format. The model is missing. The correct one is as below.

Risks

The correct form of presentation is as below:

1. Risks

a. employees  

              a. physical illness

              b. mental illness

              c. death  

2. Customers  

              a.   complaints

              b.   downtime

3.  Benefits

However, the content seems to be complete now, and hence not anything else is required. And since its not something very tough to decide to go with, bite the bullet is certainly not an issue.  

3 0
3 years ago
What type of devices are the key board and the mouse?
Lubov Fominskaja [6]
Output device - keyboard
Input device- mouse
8 0
4 years ago
Other questions:
  • WILL MARK BRAILIEST IF ANSWERED FAST!!!
    8·1 answer
  • Approximately what percent of U.S. businesses have some form of remote work program? (from Chapter 1)
    14·1 answer
  • Deleting a footnote or endnote reference mark in a document only deletes the reference mark but not the actual footnote or endno
    14·1 answer
  • 1) Open the file DiceSimulation.java attached below. Create a new project on NetBeans called DiceSimulation. Copy the code from
    13·1 answer
  • Which of the following Google tools support collaboration? Docs Sheets Slides All of the Above
    13·1 answer
  • ______________ in SONET are analogous to the ________________ of T-carriers.
    7·1 answer
  • On the 80x86 CPU, the ESP register keeps track of the value on the top of the runtime stack.
    11·1 answer
  • Finish the code where it says //YOUR CODE HERE
    11·1 answer
  • Why is information broken down into packets
    15·1 answer
  • What is the purpose of indexing?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!