Skip to content

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

@dorozhkoanton

Description

@dorozhkoanton

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions