map for storing indices of string which are in same group
map < string , vector < int > > groupMap ; for ( int i = 0 ; i < n ; i ++ ) { string diffStr = getDiffString ( str [ i ] ) ; groupMap [ diffStr ] . push_back ( i ) ; }