Sort values by how often they appear, ascending; when two values have the same frequency, put the larger value first. The whole problem is really about writing a correct composite sort key.
Count frequencies, then sort with key (frequency, -value). The negative value flips the tie-break to descending without a custom comparator.
from collections import Counter
def frequency_sort(nums):
c = Counter(nums)
return sorted(nums, key=lambda x: (c[x], -x))
O(n log n) time, O(n) space for the counter.
Candidates often sort the distinct values and forget to repeat each one by its count, or get the tie-break direction backwards. Walk through [2,3,1,3,2] out loud: 1 appears once, then 2 and 3 both twice, so 3 comes before 2, giving [1,3,3,2,2].
The hard part of easy problems is explaining them crisply under time pressure. Practice narrating the approach, the complexity and one edge case in under a minute. Disclosure: I work on Linkjob AI, a real-time interview assistant. If you want live practice help, see https://www.linkjob.ai/.
Further reading: Linkjob AI resource directory