leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

Bug Report for top-k-elements-in-list

Open Babyface2003 opened this issue 2 months ago • 1 comments

Bug Report for https://neetcode.io/problems/top-k-elements-in-list

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: res = {} freq = [[] for i in range(len(nums) + 1)] for num in nums: res[num] = res.get(num, 0) + 1 for num, cnt in res.items(): freq[cnt].append(num) arr = [] for i in range(len(nums), 0, -1): -- here for num in freq[i]: arr.append(num) if len(arr) == k: return arr return arr

Babyface2003 avatar Oct 05 '25 10:10 Babyface2003

Could you describe the issue?

Srihari2222 avatar Oct 20 '25 14:10 Srihari2222