Given an array of integers nums, sort the elements by their frequency in descending order (most frequent first).
If two elements have the same frequency, maintain their original relative order from the input array (stable sort).
Return the sorted array.
nums = [2, 3, 1, 3, 2][2, 2, 3, 3, 1]nums = [5, 5, 4, 6, 4, 4][4, 4, 4, 5, 5, 6]nums = [1][1]1 <= nums.length <= 10^4-10^5 <= nums[i] <= 10^5Run your code to see results
Use Cmd+Enter to run