For the answer given in part 2, the space required seems to be the sum from 1 to n of n which is n(n+1)/2. This gives O(n**2) for space requirements. Doesn't it?
Why cant we just sort the input (array)? Will this not mean the smallest number between x and y is always x?