Valid test case?


  • 1
    V

    For the test case:

    ["LFUCache","set","set","set","set","get","get"]
    [[2],[2,1],[1,1],[2,3],[4,1],[1],[2]]
    

    The judge's expected answer is:

    [null,null,null,null,null,-1,3]
    

    ... implying that 1 should be evicted when 4 is inserted into cache, and 2 remains.

    However, note that neither 1 nor 2 has been accessed at the time of insertion of 4. The question does not clarify the winner in this case. So either 1 or 2 could be evicted. The test case should be adjusted, or the question should clarify the way to break tie.


  • 0
    X

    I think it says pretty clearly in the description.
    "When the cache reaches its capacity, it should invalidate the least frequently used item before inserting a new item. For the purpose of this problem, when there is a tie (i.e., two or more keys that have the same frequency), the least recently used key would be evicted."


Log in to reply
 

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