Company: PepsiCo
Difficulty: medium
Sort List Based on Frequency Design a way to sort a list of positive integers in descending order based on their frequency in the list. Elements with a higher frequency should come before those with a lower frequency. If two elements have the same frequency , they should appear in the same order as in the original list. Input Format The first line contains an integer num (N), representing the number of elements in the list. The second line contains N space-separated integers representing the elements of the list. Output Format Print N space-separated integers representing the elements of the list, sorted according to the frequency of occurrence as described above. Constraints 1 ≤ num ≤ 10 5 1 ≤ list[i] ≤ 10 5 Examples Input: 19 1 2 2 3 3 3 4 4 5 5 5 5 6 6 6 6 7 8 9 10 Output: 5 5 5 5 6 6 6 6 3 3 3 2 2 4 4 1 7 8 9 10 Explanation: The number 5 has the highest frequency (4 times). The number 6 also appears 4 times, but after 5 in the input. The numbers 3 appear 3 times, follow