Find the size of largest subset of anagram words | C ++ Program to find the size of largest subset of anagram ; Utility function to find size of largest subset of anagram ; sort the string ; Increment the count of string ; Compute the maximum size of string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int largestAnagramSet ( string arr [ ] , int n ) { int maxSize = 0 ; unordered_map < string , int > count ; for ( int i = 0 ; i < n ; ++ i ) { sort ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; count [ arr [ i ] ] += 1 ; maxSize = max ( maxSize , count [ arr [ i ] ] ) ; } return maxSize ; } int main ( ) { string arr [ ] = { " ant " , " magenta " , " magnate " , " tan " , " gnamate " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << largestAnagramSet ( arr , n ) << " STRNEWLINE " ; string arr1 [ ] = { " cars " , " bikes " , " arcs " , " steer " } ; n = sizeof ( arr1 ) / sizeof ( arr [ 0 ] ) ; cout << largestAnagramSet ( arr1 , n ) ; return 0 ; }