Number of Larger Elements on right side in a string | Java program to find counts of right greater characters for every character . ; Driver code
class GFG { static void printGreaterCount ( String str ) { int len = str . length ( ) , right [ ] = new int [ len ] ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { if ( str . charAt ( i ) < str . charAt ( j ) ) { right [ i ] ++ ; } } } for ( int i = 0 ; i < len ; i ++ ) { System . out . print ( right [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { String str = " abcd " ; printGreaterCount ( str ) ; } }