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]
1 year 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]1 year 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
Quick SearchLinks to an external site. lets you refine or narrow your search results using links on the right side of the screen
nikdorinn [45]

Answer:

Answer is

By topic, By collection.

Refer below.

Explanation:

Quick SearchLinks to an external site. lets you refine or narrow your search results using links on the right side of the screen. Do a search on wind power. Some criteria that can refine your search results in Quick Search are:

By topic

By collection

5 0
3 years ago
it says i have brainly plus subscripton but whenever i log onto brainly using my laptop, it says i don't have brainly plus and w
Sladkaya [172]

Answer:

Explanation:

I think you can try logging out from your account. Try cancelling your subscription. Before you do that, reach out to Brainly support.

4 0
3 years ago
You just recently opened a business that will be selling items on the Internet. You don’ t actually have a physical store that p
Ivanshal [37]

Answer:

Explanation:

Shipping fee is based on the weight of the item purchased

Name of the store- MIMI Electronics

Items sold- Consumer electronics, mobiles phones, laptops, wearable devices, accessories, digital watches etc

Shipping charges-

Weight Shipping fee

0-1 kg $      5.00

1-2 kg $   10.00

2-4 kg $   15.00

4-7 kg $   20.00

7-10 kg $   30.00

10 kg + $   50.00

Shipping fee function

F(x)= 5 for all x [0,1]

F(x)= 10 for all x (1,2]

F(x)= 15 for all x (2,4]

F(x)= 20 for all x (4,7]

F(x)= 30 for all x (7,10]

F(x)= 50 for all x (10,infinity)

shipping charge function is a step function where the steps are mentioned in terms of weight.

Shipping charge could also be determined using a piece wise function where the shipping fee is fixed for each piece and is charged based on number of pieces ordered instead of weight of the order

5 0
2 years ago
Which of the following mountain ranges stretches from Alabama to Canada?
Vikki [24]
The Appalachian Mountains
4 0
3 years ago
How is peace circulated?​
Agata [3.3K]

Answer:

Peace is when people are able to resolve their conflicts without violence and can work together to improve the quality of their lives. 

6 0
3 years ago
Read 2 more answers
Other questions:
  • In a paragraph of no less than 125 words, explain what netiquette is and how it improves efficiency and productivity in the work
    14·1 answer
  • What is are example of an engineered item?
    12·1 answer
  • _____ is when network managers deal with network breakdowns and immediate problems instead of performing tasks according to a we
    9·1 answer
  • Look act the picture
    5·1 answer
  • Token stories of success and upward mobility (illustrated by Oprah, Ross Perot, and Madonna) reinforce ________ and perpetuate t
    8·1 answer
  • Which of the following combines something you know, such as a password, with something you are (a biometric device such as a fin
    13·1 answer
  • What is the output of the following program?
    10·1 answer
  • This is pixlr
    6·1 answer
  • What is the purpose of this parallelogram shape in a flowchart? O decision process o input or output start or end​
    13·1 answer
  • hey guys just dropped some hot beats so go and follow me my user is the beats and comment if you would do that that would be gra
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!