Frequency array to store the frequency of the first character of every string in the array
int [ ] freq = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] . charAt ( 0 ) - ' a ' ] ++ ;