It is the algorithm to find first missing nonnegative number in the array. What I like the algorithm is to work with the constraint. The constraint is that the array cannot be modified, and then second algorithm is to modify the array.
I like to work on the algorithm one more time. Here is my C# practice for the first solution without changing the input array. And here is the second solution to change the input array.
Google and find algorithms in Leetcode related to the algorithm.