Dsa
Heap
Easy
Top N Frequent Elements
Given a list of integers, implement a program to find the top N most frequent elements. If two elements have the same frequency, return the larger element first. The input begins with an integer N (the number of top frequent elements to find) followed by a list of integers. The output should be the top N frequent elements in descending order.
Example Input:
2
1
1
1
2
2
3
3
3
Example Output:
1
3
Key concepts
heapfrequency counttop k
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now