Question? Does the instructions means first missing positive integer ever or the first missing positive integer in the given sample set. What I meant is for the array [5000, 4999, 4998, 4996], if applied the second meaning then the answer is 4997 but if applied the first meaning then the answer is 1. This code is not able to be handle the second meaning. Am I missing something here?
@SM54 not sure you still need my answer but one of the examples would be the type of tasks which works with grids (int) and traverses them. If you need to keep the visited cells one option is to have boolean array which would take n*m memory. Instead of it you can use Set<Integer> and encode the coordinates in it during write and check. See "Spiral Matrix" task as the example
Another example is https://discuss.leetcode.com/topic/50837/the-most-concise-java-solution-possible-beats-99-with-explanation - I used this idea to encode number positions into the array before sorting, thus I used O(1) memory to solve the problem