Anagram Groups
Given a list of strings, write a function to group the strings into sets of anagrams.
Two strings are considered anagrams if they have the same characters, but in a different order.
Function Signature:
def group_anagrams(strings: List[str]) -> List[List[str]]:
"""
Group the given list of strings into sets of anagrams.
Parameters:
- strings: List of strings.
Returns:
- List[List[str]]: List of groups, where each group contains anagrams.
"""
# Your code here
Example:
# Input: ["listen", "silent", "enlist", "heart", "earth", "night", "thing"]
# Output: [["listen", "silent", "enlist"], ["heart", "earth"], ["night", "thing"]]
# Input: ["abc", "a", "b"]
# Output: [["abc"], ["a"], ["b"]]
Note:
- The order of the groups in the output does not matter.
- The order of strings within each group does not matter.
- All input strings consist of lowercase English letters.
Instructions:
- Write the
group_anagrams
function to solve the problem. - Implement your solution in Python.
- Feel free to use helper functions if needed.
- Provide clear comments in your code.
- Discuss the time and space complexity of your solution.
As always, we’ll share our solution to this problem tomorrow. Stay tuned 😊