Find the next greater element to the right
while ( r < ( int ) ( A . size ( ) ) ) { if ( ( int ) A [ idx ] > A [ r ] ) { ++ r ; } else { break ; } } if ( r >= ( int ) ( A . size ( ) ) r == idx ) { r = -2 ; }