Insert all positions of every character in the given String .
List < int > [ ] pos = new List < int > [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) pos [ i ] = new List < int > ( ) ; int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) pos [ str [ i ] ] . Add ( i + 1 ) ;