Hard Hashing

LRU Cache

Receives a cache capacity and a sequence of put/get operations (semicolon-separated put:key:value / get:key commands) and replays that sequence against a Least Recently Used cache built with that capacity. It maintains the cache as a hash map (key to node) paired with an explicit doubly linked list ordered from most- to least-recently-used: every get moves the accessed key to the front (or returns -1 if the key is absent), and every put either updates and moves an existing key to the front or inserts a new one at the front, evicting the entry at the back (the least recently used) whenever this pushes the cache past capacity — giving O(1) time for both operations. Returns the ordered results of each get command in the sequence, using -1 for a cache miss.

Visualization

Input

Algorithm code

Custom input

Saved inputs

References