sets all repeating characters to - 2 and non - repeating characters contain the index where they occur
for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( fi [ str [ i ] ] == -1 ) { fi [ str [ i ] ] = i ; } else { fi [ str [ i ] ] = -2 ; } } int res = INT_MAX ; for ( int i = 0 ; i < 256 ; i ++ ) {