Hash array to set which character is present in the current string
bool [ ] hash = new bool [ MAX ] ; for ( int j = 0 ; j < str . Length ; j ++ ) { hash [ str [ j ] - ' a ' ] = true ; } for ( int j = 0 ; j < MAX ; j ++ ) {