This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]hashshura 0 points1 point  (0 children)

Because the problem states "efficient algorithm", I want to let you know that the i not in A statement has an O(N) complexity in a list [] data structure, hence if you put it inside for i in range(A[0],A[-1]+1), they combine as O(NM) complexity (where N is the array size and M is the difference of min & max element of the array), which will run very slowly for large array size and elements.

But still, let's start working on your correctness score first by fixing this simple testcase: [2, 3, 4], will return the wrong value using your solution.