Z28

LFU Cache Design

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: ARRAY

Problem Statement & Objective

Design and implement a data structure for a Least Frequently Used (LFU) cache with O(1) time complexity for both get and put operations.

Function Signature (Python)

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

Input & Output Contract

Output Rule:Get işlemlerinin tam sayı sonuçları listesi.

System Constraints

0 <= kapasite <= 10^4
1 <= islemler.length <= 10^5
anahtarlar, değerler tam sayı

Example Execution Walkthrough

kapasite = 2
put(1, 1), put(2, 2), get(1)->1, put(3, 3) (2 atılır, çünkü 1'in frekansı 2, 2'nin 1), get(2)->-1, get(3)->3
cevap: [1, -1, 3]

Example Test Scenarios (3)

Example 1
Input:[2,[["put",1,1],["put",2,2],["get",1],["put",3,3],["get",2],["get",3]]]
Expected Output:[1,-1,3]
Example 2: Kapasite 0
Input:[0,[["put",0,0],["get",0]]]
Expected Output:[-1]
Example 3: Single Element
Input:[2,[["put",1,10],["get",1]]]
Expected Output:[10]
Loading Python Editor...
Input Parameters
[
  2,
  [
    [
      "put",
      1,
      1
    ],
    [
      "put",
      2,
      2
    ],
    [
      "get",
      1
    ],
    [
      "put",
      3,
      3
    ],
    [
      "get",
      2
    ],
    [
      "get",
      3
    ]
  ]
]
Expected Output
[
  1,
  -1,
  3
]