Given an array of strings, group anagrams together.
Explanation: Step 1: Create a hashmap to store anagrams. Initialize an empty hashmap with default value as an empty list. Step 2: Iterate over each string in the input array. Sort the characters in the string and use it as a key in the hashmap. Step 3: Append the string to the corresponding list in the hashmap. Step 4: Return the values of the hashmap as a list of lists.
Explanation: Step 1: Create a hashmap to store anagrams. Initialize an empty hashmap with default value as an empty list. Step 2: Iterate over each string in the input array. Sort the characters in the string and use it as a key in the hashmap. Step 3: Append the string to the corresponding list in the hashmap. Step 4: Return the values of the hashmap as a list of lists.
Analyze constraints and compute optimal solutions step-by-step.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak