First Missing Positive

Hard · Arrays & Strings · about 25 minutes

Asked at Amazon, Google, Bloomberg, Meta, Microsoft, D. E. Shaw.

nums is unsorted and may contain any integers. Report the lowest positive integer (1, 2, 3, …) that is absent from it. Your solution has to be O(n) time with O(1) extra memory.

Related guides