Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: An LRU cache holds 3 entries. Keys are accessed in this order: 1, 2, 3, 1, 4, 2, 5, 1, 3, 4. A key is a hit if it is already cached (and becomes most recent); otherwise it is a miss and the least recently used key is evicted when the cache is full. How many hits occur?

  1. A. 1
  2. B. 2
  3. C. 0
  4. D. 3

Correct answer: A. 1

Track recency order: a hit moves the key to most-recent and a miss evicts the oldest entry. Evicting the most recently used key instead gives a different hit count.

More Coding Interview Problems questions

Exams that ask this topic