In other words, find the lowest positive integer that does not exist in the array. The array can contain duplicates and negative numbers as well. This question was asked by Stri
I solved the problem using set in python3. It is very simple 6LOC. time complexity: O(n).
Remember: Membership check in set is O(1)
def first_missing_positive_integer(arr): arr = set(arr) for i in range(1, len(arr)+2): if i not in arr: return i