How about something simple:
1) Divide the array into numbers equal to and below 1000 and above
2) If all numbers correspond to the bottom section, select 1001 (or any number greater than 1000), and we are done.
3) Otherwise, we know that there must be a number from 1 to 1000, which does not exist in the lower section.
4) Create an array of elements with a size of 1000 bools elements or a 1000 element long bit field or something else and initialize the array for all
5) For each integer in the lower section, use its value as an index in the array / bitfield field and set the corresponding bool to true (i.e., sort by the radix method)
6) Scroll through the array / bitfield and select any index of the unspecified value as the solution
This works in O (n) time, or since we limited everything to 1000, technically it is O (1), but O (n) time and space in general. There are three passes over the data, which is not necessarily the most elegant approach, but the complexity remains O (n).
source share