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
using System ; using System . Collections . Generic ; class GFG { static int largestAnagramSet ( String [ ] arr , int n ) { int maxSize = 0 ; Dictionary < String , int > count = new Dictionary < String , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { char [ ] temp = arr [ i ] . ToCharArray ( ) ; Array . Sort ( temp ) ; arr [ i ] = new String ( temp ) ; if ( count . ContainsKey ( arr [ i ] ) ) { count [ arr [ i ] ] = count [ arr [ i ] ] + 1 ; } else { count . Add ( arr [ i ] , 1 ) ; } maxSize = Math . Max ( maxSize , count [ arr [ i ] ] ) ; } return maxSize ; } public static void Main ( String [ ] args ) { String [ ] arr = { " ant " , " magenta " , " magnate " , " tan " , " gnamate " } ; int n = arr . Length ; Console . WriteLine ( largestAnagramSet ( arr , n ) ) ; String [ ] arr1 = { " cars " , " bikes " , " arcs " , " steer " } ; n = arr1 . Length ; Console . WriteLine ( largestAnagramSet ( arr1 , n ) ) ; } }