Implement a recency cache and min-coins DP
Problem 1: LRU Cache Implementation
Design and implement a fixed-capacity, in-memory key-value cache that adheres to the Least Recently Used (LRU) eviction policy. When the cache is full and a new item is to be added, the least recently accessed item must be removed.
You need to implement the following methods:
Cache(int capacity): Initializes the cache with a given positivecapacity.int get(int key): Retrieves the value associated withkey. Ifkeyexists, its access counts as a recent use. Returns the value if found, otherwise returns-1.void put(int key, int value): Inserts or updates akey-valuepair. Ifkeyalready exists, its value is updated, and its access counts as a recent use. Ifkeydoes not exist and the cache is atcapacity, the least recently used item is evicted before the new item is added.
Both get and put operations must achieve an average time complexity of O(1).
Problem 2: Minimum Coin Change
Given a list of positive integer coin denominations and a targetAmount, determine the minimum number of coins required to form exactly the targetAmount. Each coin denomination can be used any number of times.
If the targetAmount cannot be formed using the given denominations, return -1.
AI interview prep
Core dilemma
Demonstrating proficiency in two distinct fundamental computer science paradigms (data structures for efficient cache management and dynamic programming for combinatorial optimization) under strict performance constraints, while managing time effectively in an interview setting.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement a recency cache and min-coins DP
Problem 1: LRU Cache Implementation
Design and implement a fixed-capacity, in-memory key-value cache that adheres to the Least Recently Used (LRU) eviction policy. When the cache is full and a new item is to be added, the least recently accessed item must be removed.
You need to implement the following methods:
Cache(int capacity): Initializes the cache with a given positivecapacity.int get(int key): Retrieves the value associated withkey. Ifkeyexists, its access counts as a recent use. Returns the value if found, otherwise returns-1.void put(int key, int value): Inserts or updates akey-valuepair. Ifkeyalready exists, its value is updated, and its access counts as a recent use. Ifkeydoes not exist and the cache is atcapacity, the least recently used item is evicted before the new item is added.
Both get and put operations must achieve an average time complexity of O(1).
Problem 2: Minimum Coin Change
Given a list of positive integer coin denominations and a targetAmount, determine the minimum number of coins required to form exactly the targetAmount. Each coin denomination can be used any number of times.
If the targetAmount cannot be formed using the given denominations, return -1.