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?
- A. 1
- B. 2
- C. 0
- 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
- Problem: Tower of Hanoi with 6 disks, moving all disks from peg A to peg C using peg B as the spare (standard rules). How many moves does…
- Problem: Count the integers from 1 to 999 whose decimal digit sum is divisible by 7.
- Problem: Compute Euler's totient φ(n) summed over n = 1 to 30 (φ(n) counts integers in [1, n] coprime to n, with φ(1) = 1).
- Problem: How many positive divisors does 720 have?
- Problem: Find the modular inverse of 7 modulo 26 (the value x with 0 ≤ x < 26 such that 7x ≡ 1 mod 26).
- Problem: A Gray code of 4 bits is generated as g = n XOR (n >> 1) for n = 0 to 15. What is the Gray code value of n = 11?