Instead of re - initialising boolean vector every time we just reset all visited letter to false
for ( int j = 0 ; j < str [ i ] . length ( ) ; ++ j ) { visited [ str [ i ] . charAt ( j ) - ' a ' ] = false ; } }