Back to the 100
Problem 076Design
Medium

LRU Cache

076

Simulate an LRU cache. Operations are put and get. Return outputs for get operations.

EXAMPLES

Example 1
Input
{
  "capacity": 2,
  "operations": [
    "put",
    "put",
    "get",
    "put",
    "get",
    "put",
    "get",
    "get",
    "get"
  ],
  "values": [
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      1
    ],
    [
      3,
      3
    ],
    [
      2
    ],
    [
      4,
      4
    ],
    [
      1
    ],
    [
      3
    ],
    [
      4
    ]
  ]
}

Output
[
  1,
  -1,
  -1,
  3,
  4
]

FUNCTION SHAPE

capacity: intoperations: stringArrayvalues: intMatrixintArray
00:00
1 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.