Using stacked for loops in Java to find the missing number in an array |
In O(n2) time, I need to identify the missing number in an array. I can rearrange the array so that everything is in order, but I can't identify the missing number without executing another for loop, which I can't do. This is my code: The missing number in this case is 3.
Code: public static void main(String[] args){ I read an article online that said I could only do two loops and had to do two loops for O(n2). They also stated that for each value, loop through all values (inner loop) and find the smallest value greater than the current value. Skip if no higher value is found. |
Welcome Guest, Not a member yet? Register Sign In |