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;
}
Answer:
The correct answer for the given question is " The Code fragment A runs fastly than the code fragment of B".
Explanation:
In this question there are some information is missing i. e options. The question does not give any options. The options for the given question is given below
(A.) The Code fragment A runs fastly than the code fragment of B.
(B.) The Code fragment B runs fastly than code fragment of A.
(C) The Code fragment A runs as fastly as code fragment of B.
So we conclude the answer i.e option(A) because As given in the question list1 is a MyArrayList and list2 is a MyLinkedList. , in list1 we fetching the data easily and fastly means that it remove the data easily as compare to list2 As MyArrayList is storing the list only and also we can fetch the data easily manner.
The list2 is an object of MyLinkedList means that it manipulating the data fastly as compared to MyArrayList but if we compared the fetching of data then MyArrayList is a better option so the code fragment runs fastly then code fragmented B.
Explanation:
Blackbaud's software products are specially designed to support the unique needs of nonprofit and social good organizations.
Explore our software solutions that can help you advance your organization's mission.