Sort by frequency
Your task
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.
Examples
frequency_sort(nums: list[int]) -> list[int]Example 1
Input
frequency_sort([1, 1, 2, 2, 2, 3])Output
[3, 1, 1, 2, 2, 2]