Testing for the presence of a number in a set is fast in Python so you could try something like this: def minpositive(a): A = set(a) ans = 1 while ans in A: ans += 1 return ans
Here is what the above code is Doing:
1. It creates a set from the list.
2. It initializes the answer to 1.
3. It checks if the answer is in the set.
4. If it is, it increments the answer and goes back to step 3.
5. If it isn’t, it returns the answer.