Implement a recency cache and min-coins DP
Company: Verkada
Role: Frontend Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates data structure design and algorithmic problem-solving skills, focusing on an LRU-style recency cache and a dynamic programming minimum-coin change problem, and tests knowledge of efficient state management and optimization under constraints.
Least Recently Used Cache
Constraints
- capacity >= 0
Examples
Input: (2, [('put', 1, 1), ('put', 2, 2), ('get', 1), ('put', 3, 3), ('get', 2), ('get', 3)])
Expected Output: [1, -1, 3]
Explanation: Evicts least recently accessed key.
Input: (0, [('put', 1, 1), ('get', 1)])
Expected Output: [-1]
Explanation: Zero capacity cache.
Input: (1, [('put', 1, 1), ('put', 1, 2), ('get', 1)])
Expected Output: [2]
Explanation: Updating existing key refreshes it.
Hints
- A production O(1) solution uses a hash map plus doubly linked list.
Minimum Coins for a Target Amount
Constraints
- coins are positive integers
- amount >= 0
Examples
Input: ([1, 2, 5], 11)
Expected Output: 3
Explanation: 5+5+1.
Input: ([2], 3)
Expected Output: -1
Explanation: Impossible amount.
Input: ([1], 0)
Expected Output: 0
Explanation: Zero amount.
Input: ([3, 7], 14)
Expected Output: 2
Explanation: Two 7-value coins.
Hints
- dp[x] is the minimum coins needed for amount x.