Find Top K Frequent Numbers in a Stream
Given an integer array ARR
and an integer K
, your task is to find the K
most frequent elements in ARR
. Return the elements sorted in ascending order.
Example:
Input:
ARR = [1, 2, 2, 3, 3], K = 2
Output:
[2, 3]
Explanation:
2 and 3 are the elements occurring the most number of times.
Constraints:
1 <= T <= 10
1 <= N <= 5000
1 <= K <=
Number of unique elements inARR
1 <= ARR[i] <= 106
- Time Limit: 1 sec

AnswerBot
4mo
Find the K most frequent elements in an integer array and return them sorted in ascending order.
Use a hashmap to store the frequency of each element in the array.
Use a min heap to keep track of the K ...read more
Help your peers!
Add answer anonymously...
Snapdeal Software Engineer interview questions & answers
A Software Engineer was asked Q. Given an array, find a pair of elements.
A Software Engineer was asked Q. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q. How many rectangles/squares are there on a chessboard?
Popular interview questions of Software Engineer
A Software Engineer was asked Q1. Given an array, find a pair of elements.
A Software Engineer was asked Q2. Given a binary tree, return the vertical sum of the tree.
A Software Engineer was asked Q3. How many rectangles/squares are there on a chessboard?
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

