Why is it the wrong answer?


  • 2
    R

    Given:
    set(key, value) - Set or insert the value if the key is not already present

    But for the following input
    Input: 2,[set(2,1),set(2,2),get(2),set(1,1),set(4,1),get(2)]

    set(2,2) shouldn't be considered because key '2' is already present in the cache with value '1'.
    so the value for key '2' in the cache should be '1'.

    But m getting

    Output: [1,-1]
    Expected: [2,-1]

    expected should be [1,-1]


  • 1
    M

    set(2,2) overwrites the (2,1) value, it doesn't get ignored. The only thing that gets ignored is when you get(x) when x is not a key in the list. The result of get(2) is the new value, 2.


  • 0
    R

    ya got it. Thanks a lot
    But the statement
    "Given: set(key, value) - Set or insert the value if the key is not already present"
    doesn't agree with what they are expecting


Log in to reply
 

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