MediumNo. 2631
Group By — LeetCode 2631 Python Solution
- Topics
- JavaScript
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Write code that enhances all arrays such that you can call the array.groupBy(fn) method on any array and it will return a grouped version of the array. A grouped array is an object where each key is the output of fn(arr[i]) and each value is an array containing all items in the original array which generate that key.
Example
- Input
- array = [
- Output
- {
Complexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
| 0228 | Summary Ranges | Easy |
Frequently asked questions
- How hard is LeetCode 2631. Group By?
LeetCode 2631. Group By is rated Medium on LeetCode.
- What topics does LeetCode 2631. Group By cover?
LeetCode 2631. Group By is tagged JavaScript on LeetCode.