For the length of strictly larger numbers on the right of A [ i ]
for ( let i = N - 1 ; i >= 0 ; i -- ) { let count = 1 ; while ( r . length != 0 && r [ r . length - 1 ] [ 0 ] >= arr [ i ] ) { count += r [ r . length - 1 ] [ 1 ] ; r . pop ( ) ; } r . push ( [ arr [ i ] , count ] ) ;