Possible Duplicate:
Find the Smallest Integer Not in a List
I got asked this question in an interview
Given an unsorted array, find the smallest number that is missing. Assume that all numbers are postive.
input = {4,2,1,3,678,3432}
output = 5
Sorting it was my first approach. Second approach of mine is to have a boolean flag array.The second approach takes up lots of space.
Is there any other better approach than this ?