The answer is not quite right...


  • 0
    B

    Hi guys, I just submitted my code for OJ... And it complains about following wrong answer...

    Input: 2,[set(2,1),set(1,1),get(2),set(4,1),get(1),get(2)]
    Output: [1,1,-1]
    Expected: [1,-1,1]

    IMO my output is right while the expected answer is wrong... any correction?


  • 3
    M

    I believe you are not updating the queue on a successful get(). Your answer is incorrect, as shown below:
    Input: 2,[set(2,1),set(1,1),get(2),set(4,1),get(1),get(2)]

    Maximum capacity is size 2.

    set(2,1)

    {(2,1)}
    

    set(1,1)

    {(2,1),(1,1)}
    

    get(2) prints 1

    {(1,1),(2,1)}
    

    set(4,1)

    {(2,1),(4,1)}
    

    get(1) prints -1

    {(2,1),(4,1)}
    

    get(2) prints 1

    {(4,1),(2,1)}
    

    result = [1,-1,1]


Log in to reply
 

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