Trivia Score Bands
Easy · hash map
A trivia night splits the players into score bands of ten points: one band is the scores 0 to 9, the next is 10 to 19, then 20 to 29, and so on. You are given the list scores, one score per player, in the order the players finished.
Group the scores by band and return a list of groups, where each group is a list of the scores that fall in one band.
- Only create a group for a band that actually has at least one score.
- Inside a group, keep the scores in the same order as in
scores. - Order the groups by first appearance: the group whose band showed up first in
scorescomes first.
Examples
Example 1
Input: scores = [42, 7, 45, 13, 9, 18]
Output: [[42, 45], [7, 9], [13, 18]]
42 and 45 are in the 40s. 7 and 9 are in the 0 to 9 band. 13 and 18 are in the teens. The 40s band appeared first, so it is the first group.
Example 2
Input: scores = [30, 10, 30]
Output: [[30, 30], [10]]
Example 3
Input: scores = [5]
Output: [[5]]
Constraints
- 1 <= len(scores) <= 2000
- 0 <= scores[i] <= 10^6