Code Room
CodingMediumcod-g206
Subject Sorting variantsLevel Mid–Senior~20 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given an integer array, return it sorted so that elements appear in increasing order of frequency (how many times they occur). Among elements with the same frequency, the one with the larger value comes first. Every occurrence of a value stays grouped together. The array has length >= 1. For example [2,3,1,3,2] becomes [1,3,3,2,2]: value 1 has frequency 1 so it leads; values 2 and 3 both have frequency 2, and 3 > 2 so the 3s precede the 2s.

Implement
frequency_sort(nums: list[int]) → list[int]
Examples
in[[1,1,2,2,2,3]]out[3,1,1,2,2,2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.