Sort by Frequency and Value
Given a list of integers nums, order nums by frequency, with most frequent values coming first. If there’s a tie in frequency, higher valued numbers should come first.
Constraints
0 ≤ n ≤ 100,000wherenis the length ofnums
https://binarysearch.com/problems/Sort-by-Frequency-and-Value
Examples
Example 1
Input
- nums =
[1, 1, 5, 5, 5, 2, 2, 2, 1, 1]
Output
- answer =
[1, 1, 1, 1, 5, 5, 5, 2, 2, 2]
Explanation
Since 1 occurs most frequently (4 times) they come first. 5 and 2 are then tied in terms of frequency (both 3 times) but 5 has higher value so it comes second.
Leave a comment