for every j greater than i
for ( int j = n - 1 ; j > i ; j -- ) { if ( ( arr [ j ] < arr [ i ] ) && ( LDS [ j ] . size ( ) > LDS [ i ] . size ( ) ) ) LDS [ i ] = LDS [ j ] ; } LDS [ i ] . push_back ( arr [ i ] ) ; }