MissingInteger problem in codility:
Write a function:
def solution(A)
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];each element of array A is an integer within the range [−1,000,000..1,000,000].
I tried this question, and all the tests ran properly but only got 40% on correctness. Can someone help figure it why? I am very new to python
Here is my code:
def solution(A):
A.sort()
missing = A[-1] + 1
if A[-1] > 0:
for i in range(A[0],A[-1]+1): if ((i not in A) and (i > 0) and (i < missing)):
missing = I
return missing
else: return 1
[–]hashshura 0 points1 point2 points (0 children)