coding•DSA & Problem Solving•Strings & Hash Tables
Group Anagrams by Frequency Signature
Problem Statement
Given an array of strings `strs`, group the **anagrams** together. You can return the answer in any order.
An **Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
### Constraints
- `1 <= strs.length <= 10^4`
- `0 <= strs[i].length <= 100`
- `strs[i]` consists of lowercase English letters.
### Input Format
A single line of space-separated strings.
### Output Format
Print the number of anagram groups formed, followed by each group's count and words sorted lexicographically. For canonical grading across languages, return a list of lists of strings where groups are sorted by the first word in each group.
Sample Cases
Example 1Sample Case
Input: eat tea tan ate nat bat
Output: ate eat tea
bat
nat tan
Example 2Sample Case
Input: a
Output: a
Example 3Sample Case
Input: e
Output: e
Example 4Sample Case
Input: ea
Output: ea
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.