Top K Frequent Elements
Updated Feb 24, 2026
Problem
Return top k frequent numbers sorted ascending by value in ties.
Constraints
1 <= nums.length <= 10^5
Examples
Example 1
Input:
{"nums": [1, 1, 1, 2, 2, 3], "k": 2}
Output:
[1, 2]
Function Signature
def topKFrequent(self, nums: list[int], k: int) -> list[int]
How to Submit
Implement a Solution class with a topKFrequent method.
Your method will be called with the input parameters and should return the answer.