FunctionRacerProblemsRace

Frequency Buckets

EasySorting and searchingPython, JavaScript, TypeScript, Java, C++

Count how many times each value appears in nums. Build a list of buckets: bucket 0 holds every distinct value that appears exactly once, bucket 1 every distinct value that appears exactly twice, and so on. Each bucket lists its values in increasing order, each value once. The list of buckets ends at the bucket of the highest count, and a bucket with no values is an empty list.

Return the list of buckets. An empty nums gives [].

Example 1

nums [4,1,4,2,4,1]
returns [[2],[1],[4]]

2 appears once, 1 twice, 4 three times.

Example 2

nums [7,7,7]
returns [[],[],[7]]

7 appears three times, so the buckets for one and two appearances are empty.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems