For the length of strictly larger numbers on the left of A [ i ]
for ( int i = 0 ; i < N ; i ++ ) { int count = 1 ; while ( ! l . isEmpty ( ) && l . peek ( ) . first > arr [ i ] ) { count += l . peek ( ) . second ; l . pop ( ) ; } l . add ( new pair ( arr [ i ] , count ) ) ;