# Given an unsorted integer array, find the first missing positive integer.
#
# For example,
# Given [1,2,0] return 3,
# and [3,4,-1,1] return 2.
#
# Your algorithm should run in O(n) time and uses constant space.
class Solution():
def firstMissingPositive(self, x):
if x:
lst = list(range(1, len(x)+2))
for i in x:
if 0 < i < len(x)+1 and i in lst:
lst.remove(i)
return lst[0]
return 1
if __name__ == "__main__":
assert Solution().firstMissingPositive([1, 2, 0]) == 3
assert Solution().firstMissingPositive([3, 4, -1, 1]) == 2