Data Structures & AlgorithmsHardGATE CS · TCS NQT

An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?

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

Correct answer: A. 1

Track the recency order: after 3 evicts the least recently used key, which determines whether later requests hit.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic