Linked List pattern

LRU Cache

Design a data structure for a Least-Recently-Used (LRU) cache with a fixed capacity. Support get(key) and put(key, value), both in O(1) average time. When the cache is full, evict the least-recently-used entry. Watch it run step by step, then write your own pseudocode and get it checked by AI.

  • LeetCode 146
  • Medium
  • 1 approach

Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.

Linked ListLeetCode 146

Medium

The approach

  1. 01 Hash map + doubly linked list O(1) get / putO(capacity) space
Played step by step, with its time and space.

What you will learn

  • How to read LRU Cache and spot the linked list pattern in it
  • Hash map + doubly linked list: O(1) get / put time, O(capacity) space
  • The pseudocode for each approach, its line lit as the animation runs
  • Practice: write your own pseudocode and get it checked

More Linked List

See LRU Cache run, step by step

Sign in and this page opens on the animation, with all 9 Linked List problems beside it.

DSA comes with the all labs plan and every ChaiCode batch.