Trains the technique from
LeetCode 1636Sort Array by Increasing FrequencyThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A calibration rig logs temperature drifts into nums, where a drift may be negative, zero or positive and the same drift may be logged many times.
Rearrange the whole log so that a drift logged fewer times stands ahead of a drift logged more times. When two drifts were logged the same number of times, the larger drift comes first. Each drift must still appear exactly as many times as it did in the input, and all copies of one drift sit together.
Return the rearranged log.
Example 1
9 was logged once, 4 twice and -2 twice. The single 9 leads, then the two drifts tied on two logs each appear larger first, so both 4s precede both -2s.
Example 2
3 was logged once, 100 twice and -100 three times, so the groups come out in that order of tally.
Example 3
All three drifts were logged twice, so the tie rule alone decides and they come out from largest to smallest.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def frequency_sort(nums: list[int]) -> list[int]:public int[] frequencySort(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.