Check for a subsequence of size 2
if ( flag == false ) { for ( let j = 0 ; j < S . length ; j ++ ) { for ( let j1 = j + 1 ; j1 < S . length ; j1 ++ ) { let dummy = S [ j ] + S [ j1 ] ; if ( dummy != " " && dummy != " " && dummy != " " && dummy != " " ) { document . write ( 2 ) ; } if ( flag == true ) break ; else flag = true ; } if ( flag == true ) break ; } }