Calculate length of String
int n = s . length ( ) ; int [ ] [ ] pref = new int [ 26 ] [ n ] ; Vector < Integer > [ ] pos = new Vector [ 26 ] ; for ( int i = 0 ; i < pos . length ; i ++ ) pos [ i ] = new Vector < Integer > ( ) ; pref [ s . charAt ( 0 ) - ' a ' ] [ 0 ] ++ ; pos [ s . charAt ( 0 ) - ' a ' ] . add ( 0 ) ;