Find the size of largest subset of anagram words | 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
function largestAnagramSet ( arr , n ) { var maxSize = 0 ; var count = new Map ( ) ; for ( var i = 0 ; i < n ; ++ i ) { var temp = arr [ i ] . split ( ' ' ) ; temp . sort ( ) ; arr [ i ] = temp . join ( ' ' ) ; if ( count . has ( arr [ i ] ) ) { count . set ( arr [ i ] , count . get ( arr [ i ] ) + 1 ) ; } else { count . set ( arr [ i ] , 1 ) ; } maxSize = Math . max ( maxSize , count . get ( arr [ i ] ) ) ; } return maxSize ; } var arr = [ " " , " " , " " , " " , " " ] ; var n = arr . length ; document . write ( largestAnagramSet ( arr , n ) + " " ) ; var arr1 = [ " " , " " , " " , " " ] ; n = arr1 . length ; document . write ( largestAnagramSet ( arr1 , n ) ) ;