Group Anagrams
Write a function groupAnagrams that takes an array of strings and groups the anagrams together.
Function Signature
function groupAnagrams(strs);
Example 1:
Input:
strs = ["eat", "tea", "tan", "ate", "nat", "bat"]
Output:[["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]
Explanation: All strings that are anagrams are grouped together.
Example 2:
Input:
strs = [""]
Output:[[""]]
Explanation: An empty string is considered an anagram of itself.
Example 3:
Input:
strs = ["a"]
Output:[["a"]]
Explanation: A single character string is considered an anagram of itself.
Solve this problem
Start your 7-day free trial to solve this problem in our code editor with instant feedback.
Start 7-Day Free Trial to Solve This ProblemRelated Problems
String Compression
mediumCompress a string using the counts of repeated characters. ## Function Signature ```function compressString(chars);``` ### Example 1: > **Input:** `chars = ["a","a","b","b","c","c","c"]` \ > **Output:** `["a","2","b","2","c","3"]` \ > **Explanation:** The string compression of "aabbbccc" is "a2b2c3". ### Example 2: > **Input:** `chars = ["a","b","c"]` \ > **Output:** `["a","b","c"]` \ > **Explanation:** The string compression of "abc" is "abc" as each character appears only once.
StringValid Anagram
mediumDetermine if two strings are anagrams of each other. ## Function Signature ```function isAnagram(s, t);``` ### Example 1: > **Input:** `s = "anagram", t = "nagaram"` \ > **Output:** `true` \ > **Explanation:** The strings "anagram" and "nagaram" are anagrams of each other. ### Example 2: > **Input:** `s = "rat", t = "car"` \ > **Output:** `false` \ > **Explanation:** The strings "rat" and "car" are not anagrams.
StringLength of Last Word
mediumCalculate the length of the last word in a string separated by space characters. ## Function Signature ```function lengthOfLastWord(s);``` ### Example 1: > **Input:** `s = "Hello World"` \ > **Output:** `5` \ > **Explanation:** The length of the last word "World" is 5. ### Example 2: > **Input:** `s = " fly me to the moon "` \ > **Output:** `4` \ > **Explanation:** The length of the last word "moon" is 4.
String