about | help | code help+videos | done | prefs |
largestAnagramGroup
Given an array of strings strs, return the group of anagrams that has the largest number of strings. An anagram is a word formed by rearranging the letters of another word using all the original letters exactly once. For example, “eat”, “tea”, and “ate” are anagrams because they all contain one ‘e’, one ‘a’, and one ‘t’. If the input is [“eat”,“tea”,“tan”,“ate”,“nat”,“bat”], the output should be [“ate”,“eat”,“tea”] (all sorted) because that is the largest group of anagrams among [["bat"],["nat","tan"],["ate","eat","tea"]]. If there are multiple groups of the same maximum size, return any one of them. If the input is [””], the output is [””]. If the input is [“a”], the output is [“a”]. You must use a HashMap to group the anagrams efficiently and return the largest group. largestAnagramGroup(["eat", "tea", "tan", "ate", "nat", "bat"]) → ["ate", "eat", "tea"] largestAnagramGroup([""]) → [""] largestAnagramGroup(["a"]) → ["a"] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 310
Copyright Nick Parlante 2017 - privacy