Confused about Expected Answer

  • 0

    [in reference to 347. Top K Frequent Elements]
    I gave a custom test case of:


    And the expected answer is "[1,2,4]". My understanding of the problem, and my code's result is "[1,2,3,4]".





    This actually doesn't make sense. Shouldn't it then be [2,3,4]? It's not at all clear why the 3 is dropped. In the first case, I could accept that the most frequent elements are all accepted, and then the greatest of the next most frequent, until there are no more slots remaining. But in the second case, the accepted answer is plain nonsensical.

    In any case, even if my understanding of why the 3 was dropped in the first case is correct, the problem constraints are incomplete. But that still doesn't address why the 3 was dropped in the second case.

    Anyone with any insights?

  • 0

    Yes, I'm also quite confused about the expected answer when I run certain test cases. The expected answer will somehow drop some value in no way I could be able to understand. Is there any one who can have some words on this?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.