O01

Warehouse Cache System

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

Simulate a Least Recently Used (LRU) storage cache for inventory pallets with capacity limits and O(1) get/put operations.

Function Signature (Python)

lru_cache_operations(capacity: int, operations: list) -> list[int]

Input & Output Contract

Output Rule:Uzunluğu işlemlerdeki 'get' sayısına eşit olan tam sayı dizisi. Hiç 'get' yoksa boş dizi [].

System Constraints

1 <= kapasite <= 10^4
1 <= islemler.length <= 10^5
anahtarlar ve değerler tam sayı; -1 yalnızca 'yok' anlamına gelir

Example Execution Walkthrough

kapasite = 2
["put",1,10]   bellek: {1:10}
["put",2,20]   bellek: {1:10, 2:20} (eski -> yeni: 1, 2)
["get",1]      -> 10 bulunur, 1 en yeni olur (eski -> yeni: 2, 1) -> ÇIKTI: 10
["put",3,30]   kapasite dolu, EN ESKİ (2) atılır -> {1:10, 3:30}
["get",2]      -> yok -> ÇIKTI: -1
["get",3]      -> 30  -> ÇIKTI: 30
cevap: [10, -1, 30]

Example Test Scenarios (3)

Example 1
Input:[2,[["put",1,10],["put",2,20],["get",1],["put",3,30],["get",2],["get",3]]]
Expected Output:[10,-1,30]
Example 2: Temel Get/Put
Input:[2,[["put",1,100],["get",1],["get",2]]]
Expected Output:[100,-1]
Example 3: Kapasite 1 Tahliye
Input:[1,[["put",10,50],["put",20,60],["get",10],["get",20]]]
Expected Output:[-1,60]
Loading Python Editor...
Input Parameters
[
  2,
  [
    [
      "put",
      1,
      10
    ],
    [
      "put",
      2,
      20
    ],
    [
      "get",
      1
    ],
    [
      "put",
      3,
      30
    ],
    [
      "get",
      2
    ],
    [
      "get",
      3
    ]
  ]
]
Expected Output
[
  10,
  -1,
  30
]