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 = Int32 . MaxValue ; for ( int i = 0 ; i < 256 ; i ++ ) {