What is wrong in my python code?


#1
def solve(self, A):
    A.sort(reverse=True)
    
    if A[0]==0:
        return -1
    for i in range(len(A)):
        count=0
        for j in range(len(A)):
            if (A[j] > A[i]):
                count += 1
        if (count == A[i]):
            return 1
    return -1

#2

Hi,
Your first condition is wrong… if in the reverse sorted list first element is zero… then there are zero elements greater than zero… and so our condition becomes true… so you should return 1,
plus you could optimize your code further… like in sorted list the position of the i’th element itself tells you number of elements greater than it… so you need not count it…