This is a variation of [1]. I have a list of N (number of values N is known) non-negative integers. Upper bound of the list is 1024. What is the smallest non-negative integer not in the list?
For ex., the list could be 0,3,6,2,4,1,8,0,9,0 - then the output must be 5.
The way I am thinking of doing this - I know the length of the list will not be > 1024. So i have an array IFLAG of size 1024 - i then scan through the N numbers - if the i'th number is k, i set IFLAG[k] = 1. I also keep tab of the highest number in the list, say MAX
AFter scanning all N numbers in the list, I then scan IFLAG from 1 to (MAX+1) and identify the first location with a 0. That is my required output.
I have to repeatedly do this (thousands to even millions of times) - so, Is there a better way to do this (likely)?. Can i do this without using the IFLAG array?
Thanks Rey