The Codetikki archivists maintain a memory vault of fixed capacity. When the vault is full and a new memory must be stored, the least recently accessed memory is evicted. Implement an LRU cache with capacity n supporting: get key (returns value or -1 if not present), put key value (sets key to value, evicting LRU if at capacity). Each operation must run in O(1) time. Input: first line capacity n, second line number of operations m, then m lines each like "get k" or "put k v". Output: results of get operations, one per line.
Example 1:
Example 2:
Constraints:
1 <= capacity <= 10^4 1 <= m <= 10^5 0 <= key, value <= 10^9
Tags:
