LRU Cache Implementation
00:00
AmazonGoogleMicrosoft
Design an LRU Cache supporting get and put both in O(1) time. Evict least recently used when capacity exceeded.
Examples
Input → Ex1: cap=2,put(1,1),put(2,2),get(1)=1,put(3,3) evicts 2,get(2)=-1
Output →
Input → Ex2: cap=1,put(1,1),put(2,2) evicts 1,get(1)=-1
Output →
Input → Ex3: get non-existent key returns -1
Output →