Skip to content

python/top-k-frequent-words.md min-heap approach is wrong #5

@Rishabh-Hupr

Description

@Rishabh-Hupr

Link: https://github.com/AlgoMaster-io/leetcode-solutions/blob/main/python/top-k-frequent-words.md

Approach 2:
if we take a look closely, then it will always pop-out the maximum frequency tuple if any smaller frequency arrives after k heappushes are done.
Which makes it wrong.
I believe it's highly unlikely to have O(nlogK) for this solution.
Instead what we can do is either of the three approaches that I have defined here: https://github.com/Rishabh-Hupr/leetcode/blob/main/heaps/top-k-frequent-elements.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions