0

I have a task to find an integer, which is >0, minimal and not presented in the input array (the first int number, which higher than 0 and missed in array). Can anybody explain me, which function is better in the sense of performance?

def solution_1(A):
    for i in range(1, abs(max(A))+2):
        if i not in A:
            return(i)
            break

def solution_2(A):
    A = set(A)
    count = 1
    while count in A:
        count += 1
    return count
 

FULL STORY: I've completed demo-task (solution_1) from codility.com and I was surprised when it has shown performance score only 25%, when correctness or something was 100%. Because total score then 66% I tried to figure out how I can improve the performance and found the same completed task here. I submitted found solution (solution_2) and it has shown 100% of performance. The main difference was that I used loop "for", when found example utilized loop "while", which is slower as I know. I've checked it on a big batch of randomized arrays and the time of execution of my approach (solution_1) is 25% faster at least. Do I understand the term "performance" wrong?

affogato
  • 3
  • 3

0 Answers0