Lv.2hashsortingstring
Anagram Groups
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Anagram Groups
Given an array of lowercase words, group the words that are anagrams of each other and return the groups. Each group must be sorted in ascending lexicographic order (duplicates kept); the order of the groups does not matter.
Constraints
-
words.length,words[i].length, lowercasea–zonly.
Example
["eat", "tea", "tan", "ate", "nat", "bat"] → [["ate", "eat", "tea"], ["nat", "tan"], ["bat"]] (any group order)
Expected time complexity: . Scanning all existing groups for every word, , exceeds the performance time limit.
Function signature
solution(words: string[]) → string[][]
Expected complexity
- Time
- O(N * L log L)
- Space
- O(N * L)
Examples
| words | Expected |
|---|---|
["eat","tea","tan","ate","nat","bat"] | [["ate","eat","tea"],["nat","tan"],["bat"]] |
["a"] | [["a"]] |
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 2130 ms | derived |
| Kotlin 2.4 (JVM) | 1400 ms | estimated |
| C# 14 (.NET 10) | 1400 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 2 | inputs and outputs |
| correctness | 40 | 8 | verdict only |
| performance | 60 | 4 | verdict only |