Top K Frequent Elements

Medium Solved

Description

Given an integer array nums and an integer k, return the k most frequent elements.

You may return the answer in any order.

Input format:

  • Line 1: JSON array of integers
  • Line 2: Integer k

Examples

Input:
[1,1,1,2,2,3]
2

Output:
[1,2]
Input:
[1]
1

Output:
[1]

Note:

Print the result as a JSON array so it can be compared correctly.

No submissions yet.

Discuss hash maps, bucket sort, and heap-based solutions.

Test Cases