-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
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.
Input: nums=[1,2], k=2
Your Output: []
Expected output:[1,2] - Wrong answer! Should be []
My code:
from collections import defaultdict
class Solution:
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
counter = defaultdict(int)
for num in nums:
counter[num] += 1
result = []
for num, count in counter.items():
if count >= k:
result.append(num)
return result
Metadata
Metadata
Assignees
Labels
No labels