Group By — LeetCode 2631 Python Solution
MediumJavaScript
- Problem
- #2631
- 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
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
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.