What's wrong with this python code


#1

if len(A) == len(set(A)):
return (len(A)*(len(A)+1))/2

    A = sorted(A)
    cho = 1
    total = 1
    for i in range(1,len(A)):
        if A[i] == A[i-1]:
            total+=cho
        else:
            cho+=1
            total+=cho
    return total

#2

I got the same problem .
but when you check A=[1,5,6,2,1] output is 9 and 5,2 are getting 2 candies each…so the rating is basically depicts if the child have a higher rating then neighbor then he should get more candies then his neighbors irrespective of other elements that’s why sorting should not be done.