I don't understand why the expected output is this.
In my understanding, the 2nd set(2,2) should not have any effect on the LRU values. This is because the instruction for the set function says: "set or insert if the key is not already present". So for the 1st get(2), the output is 1. After set(1,1) and set(4,1), the key 2 is no longer in the LRU. So 2nd get(2) produces -1.
Thus, if my understanding is correct, the output should be [1,-1]. Is there anything I am not getting correctly?
Maybe @1337 need to update the problem description to clarify it.
Set or insert the value if the key is not already present.
Set a new value of the key which is already in cache.