Insert all positions of every character in the given String .
Vector < Integer > [ ] pos = new Vector [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) pos [ i ] = new Vector < Integer > ( ) ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) pos [ str . charAt ( i ) ] . add ( i + 1 ) ;