Occur [ i ] stores the indices of char ( ' a ' + i ) in String s
List < int > [ ] occur = new List < int > [ 26 ] ; for ( int i = 0 ; i < occur . Length ; i ++ ) occur [ i ] = new List < int > ( ) ; for ( int x = 0 ; x < n ; x ++ ) { char ch = ( char ) ( s [ x ] - ' a ' ) ; occur [ ch ] . Add ( x ) ; }