Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: An LRU cache of capacity 2 handles requests 1, 2, 1, 3, 2, 1, 4. Each request that is not cached causes a miss and evicts the least recently used item if the cache is full. How many misses occur?
- A. 5
- B. 4
- C. 6
- D. 7
Correct answer: C. 6
LRU: 1 m, 2 m, 1 h, 3 m (evict 2), 2 m (evict 1), 1 m (evict 3), 4 m (evict 2): 6 misses. FIFO (no move on hit) gives 5, counting distinct keys gives 4, and 7 treats every request as a miss.
More Coding Interview Problems questions
- Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?
- Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are…
- Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3…
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?