Top K Frequent Elements

easy
1.Given a non-empty array of integers. 2.You have to find the k most frequent elements. 3.You have to complete the topKFrequent() function which should return the list of k most frequent elements.

Input Format

1.First line contains an integr 'N' denoting the size of the array. 2.Second line contains 'N' space separated elements 3.Third line contains an integer 'K'.

Output Format

Return the array list of integer in any order.

Constraints

1 <= k <= number of unique elements.

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6
1 1 1 2 2 3
2
Output
[1, 2]
Previous
Tom And String
Next
Top-k-frequency Words

Related Questions