Confused about Expected Answer


  • 0
    J

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

    [1,1,1,2,2,2,3,3,4,4,5,6]
    3

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

    Similarly:

    [1,1,1,2,2,2,3,3,3,4,4,4,5,6]
    3

    Produces:

    [1,2,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
    C

    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.