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
class GFG { static void countSmaller ( String str ) { int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( str . charAt ( j ) < str . charAt ( i ) ) { cnt += 1 ; } } System . out . print ( cnt + " ▁ " ) ; } } public static void main ( String [ ] args ) { String str = " edcba " ; countSmaller ( str ) ; } }