Count smaller elements present in the array for each array element | Function to count for each array element , the number of elements that are smaller than that element ; Traverse the array ; Stores the count ; Traverse the array ; Increment count ; Print the count of smaller elements for the current element ; Driver Code
def smallerNumbers ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT count = 0 NEW_LINE for j in range ( N ) : NEW_LINE INDENT if ( arr [ j ] < arr [ i ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 3 , 4 , 1 , 1 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE smallerNumbers ( arr , N ) NEW_LINE DEDENT