for every j less than i
for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && LIS [ j ] . size ( ) > LIS [ i ] . size ( ) ) { for ( int k : LIS [ j ] ) if ( ! LIS [ i ] . contains ( k ) ) LIS [ i ] . add ( k ) ; } } LIS [ i ] . add ( arr [ i ] ) ; }