Implement LRU Cache

Asked at Palo Alto Networks · Coding Questions · Difficulty: Medium · Last asked Jul 15, 2026

Implement a LRU (Least Recently Used) cache. This class must support the `get` and `put` methods. Each `get` or `put` operation should be executed in O(1) time complexity. The cache capacity is provided at initialization, and when reaching the limit, invalidate the least recently used item before adding a new one. In the `put` method, if a new element already exists, its value needs to be updated. Please provide full interface specifications and test cases.

Loading the problem…