If same == true then it means a substring was found starting at position therefore all characters from position to length of substring found need to be changed therefore they needs to be marked
if ( same == true ) { for ( int i = position ; i < position + k ; i ++ ) pre [ i ] = true ; return ; } }