Grouping [mp]
Micro pattern¶
Description¶
Collect values sharing a level, canonical key, or derived property into one container.
Problems¶
Group by traversal level¶
Collect the current BFS frontier as a single group.
- 102. Binary Tree Level Order Traversal (Top Easy)
- 103. Binary Tree Zigzag Level Order Traversal (Top Medium)
- 329. Longest Increasing Path in a Matrix (Top Hard)
- 934. Shortest Bridge (Graph Theory)
Group by canonical key¶
Use a common representation as the grouping key.
- 49. Group Anagrams (Top Medium)
Group by frequency¶
Index the group containing a value by its occurrence count.
- 347. Top K Frequent Elements (Top Medium)
Group equal sweep coordinates¶
Apply all events at a coordinate before measuring its resulting state.
- 218. The Skyline Problem (Top Hard)
Group by assigned category¶
Preserve the internal order of each category before emitting categories in a separate order.
- 1203. Sort Items by Groups Respecting Dependencies (Graph Theory)