Sort Array by Increasing Frequency
Return nums sorted by how often each value appears, fewest first. Values with the same frequency go in decreasing order of value. Every copy of a value is kept.
Example 1
nums [1,1,2,2,2,3]
returns [3,1,1,2,2,2]
3 appears once, 1 twice, 2 three times: [3, 1, 1, 2, 2, 2].
Example 2
nums [2,3,1,3,2]
returns [1,3,3,2,2]
1 once; 3 and 2 twice each, bigger value first: [1, 3, 3, 2, 2].
Constraints
1 <= len(nums) <= 40-20 <= nums[i] <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.