All problems
Memoization Cache LRU Eviction
Problem
Simulate an LRU memoization cache for a pure function.
capacity is the maximum number of cached arguments and calls is the sequence of function arguments. A repeated argument is a hit and refreshes recency; a new argument is a miss and evicts the least recently used entry when the cache is full.
Return [hits, misses, evictions].
Hint
Keep the cache list ordered from least to most recently used.
Test cases
case 1
in: [2,[1,1,2,3,1]]
expected: [1,4,2]
case 2
in: [1,[5,5,5]]
expected: [2,1,0]
case 3
in: [3,[]]
expected: [0,0,0]
case 4
in: [2,[1,2,1,2,1]]
expected: [3,2,0]
Starter codePython
def memo_cache(capacity, calls):
# Your code here
pass4 test cases · run your code against them in the editor