Count of lexicographically smaller characters on right | function to count the smaller characters at the right of index i ; store the length of String ; for each index initialize count as zero ; increment the count if characters are smaller than at ith index ; print the count of characters smaller than the index i ; Driver code ; input String
def countSmaller ( str ) : NEW_LINE INDENT n = len ( str ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( str [ j ] < str [ i ] ) : NEW_LINE INDENT cnt += 1 ; NEW_LINE DEDENT DEDENT print ( cnt , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " edcba " ; NEW_LINE countSmaller ( str ) ; NEW_LINE DEDENT