Razorpay Payment LRU Cache
Razorpay Payment LRU Cache
HardHash Maps100% accepted
Razorpay caches recent payment results. Design an LRU (Least Recently Used) cache with get(key) and put(key,value) operations, both O(1). Evict least recently used item when capacity is exceeded.
Approach
Design LRU Cache with O(1) get and put using hash map + doubly linked list.
Input
cap=2
put(1,1)
put(2,2)
get(1)
put(3,3)
get(2)
put(4,4)
get(1)
get(3)
get(4)
Output
1 -1 -1 3 4
More Hash Maps problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards