Loading Question...
Implement an LFU (Least Frequently Used) cache of size cacheSize that supports two operations.
GET key
key.-1.PUT key value
(key, value) pair.Return an array containing the outputs of every GET query in order.
cacheSize = 1
queries =
["PUT 1 1",
"PUT 2 2",
"GET 1"]
Execution
| Query | Cache | Output |
|---|---|---|
| PUT 1 1 | {1=1} | |
| PUT 2 2 | {2=2} | |
| GET 1 | {2=2} | -1 |
Return
[-1]
implementLFU(cacheSize, queries)
int cacheSize
string queries[q]
int[]
Outputs of all GET queries.
2 ≤ cacheSize ≤ 100
1 ≤ q ≤ 10^5
At least one GET query exists.
Length of query ≤ 17
Keys and values contain digits (0-9) only.
Value of key ≤ 300
Value of value ≤ 10^5
Flipkart • Pending
Flipkart • Pending
Flipkart • Pending
Texas • Pending
BNY • Pending