Recover a Function-Call LRU Cache with a Write-Ahead Log
Problem statement
Simulate a function-call cache of positive capacity using least recently used eviction and an actual file-backed write-ahead log. Process operations in order and return one string for every operation.
Finite call adapter
A call row is ["CALL", functionId, resultValue, positionalCount, ...positionalArgs, keywordCount, key1, value1, ...]. Counts are decimal strings and each keyword name is unique within that call. Every argument and keyword value is a string. The opaque functionId identifies the supplied callable, positional arguments retain their order, and keyword dictionary insertion order does not affect identity.
Examples
Example 1
operations = [["CALL","f","A","1","x","0"],["CALL","f","A","1","x","0"],["RECOVER"],["CALL","f","A","1","x","0"]]capacity = 2return = ["VALUE:A|CALLS:1","VALUE:A|CALLS:1","RECOVERED:1|CALLS:1","VALUE:A|CALLS:1"]The second call is a hit, and recovery reloads the same key without invoking the underlying function.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.