Find how many smaller element in the right side



Problem to find the how many smallest value in right side of each element.



Example-1:


Input    : n = [ 3, 4, 9, 6, 1]
Output   : [1, 1, 2, 1, 0]   


Example-2:


Input    : n = [ 5, 3, 1, 2, 3]
Output   : [4, 2, 0, 0, 0]







Solution




n = [ 3, 4, 9, 6, 1]

l = []

for i in range(len(n)):

    count = 0

    for j in range(len(n)):

        if(i == j):

            continue

        elif(i<j):

            if(n[i]>n[j]):

                count += 1

    l.append(count)

print(l)



Output



[1, 1, 2, 1, 0]