Data structures, from scratch

A LeetCode practice list organized by data structure, roughly easy → hard within each group. These are picked because they make you actually build the structure rather than reach for a library one.

Open the full list on LeetCode

Why this list

I've been enjoying low-level programming lately, the kind where you're working with actual data structures. Two recent projects pushed me here.

The first was a key-value store in Go built around memtables, a write-ahead log, and SSTables an LSM-tree, end to end. The second was a B-tree storage engine in the spirit of Postgres: how rows are laid out on pages, how the pager reads and writes them, and how updates are made durable. All of it handwritten.

Building those was a lot of fun, and it made me realise this stuff is addictive. I'm just enjoying it as I build new things and turning them into blog posts in case they help someone. This one I actually wrote for my friend, she wanted my DS Ladder practice list, and sharing a bare LeetCode list doesn't carry any context, so I asked Claude to write one. This ladder is my way of going back through the fundamentals deliberately, one structure at a time, from scratch. I'll write up the B-tree and LSM-tree builds separately in later posts.

Arrays, two pointers, sliding window

  1. 26Remove Duplicates from Sorted ArrayEasy
  2. 3Longest Substring Without Repeating CharactersMedium
  3. 153SumMedium
  4. 42Trapping Rain WaterHard
  5. 76Minimum Window SubstringHard

Linked list build your own nodes

  1. 206Reverse Linked ListEasy
  2. 21Merge Two Sorted ListsEasy
  3. 141Linked List CycleEasy
  4. 23Merge k Sorted ListsHard
  5. 146LRU CacheDoubly linked list + hashmap combo. A classic.Medium
  6. 25Reverse Nodes in k-GroupHard

Stack and queue

  1. 20Valid ParenthesesEasy
  2. 155Min StackA stack that also tracks its minimum in O(1).Medium
  3. 232Implement Queue using StacksEasy
  4. 84Largest Rectangle in HistogramHard
  5. 239Sliding Window MaximumMonotonic deque.Hard

Hash map and hash set

  1. 1Two SumEasy
  2. 49Group AnagramsMedium
  3. 128Longest Consecutive SequenceMedium
  4. 380Insert Delete GetRandom O(1)Custom structure combining an array and a map.Medium

Binary tree

  1. 104Maximum Depth of Binary TreeEasy
  2. 226Invert Binary TreeEasy
  3. 98Validate Binary Search TreeMedium
  4. 105Construct Binary Tree from Preorder and Inorder TraversalMedium
  5. 236Lowest Common Ancestor of a Binary TreeMedium
  6. 297Serialize and Deserialize Binary TreeHard

Binary search tree

  1. 700Search in a Binary Search TreeEasy
  2. 701Insert into a Binary Search TreeMedium
  3. 450Delete Node in a BSTMedium

Heap and priority queue

  1. 215Kth Largest Element in an ArrayMedium
  2. 23Merge k Sorted ListsAgain, this time with a heap.Hard
  3. 347Top K Frequent ElementsMedium
  4. 295Find Median from Data StreamTwo heaps.Hard

Trie

  1. 208Implement Trie (Prefix Tree)Medium
  2. 211Design Add and Search Words Data StructureMedium
  3. 212Word Search IITrie built from the word list, backtracking DFS from every cell.Hard
  4. 421Maximum XOR of Two Numbers in an ArrayMedium

Graph

  1. 200Number of IslandsDFS/BFS on a grid.Medium
  2. 133Clone GraphMedium
  3. 207Course ScheduleTopological sort, cycle detection.Medium
  4. 994Rotting OrangesMulti-source BFS.Medium
  5. 269Alien DictionaryPremium, but a standard one. Topological sort on a graph you build yourself.Hard

Union-Find build this one from scratch, it comes up a lot

  1. 547Number of ProvincesMedium
  2. 200Number of IslandsSolve it again, with Union-Find instead of DFS.Medium
  3. 684Redundant ConnectionMedium

Design problems combine several structures

  1. 146LRU CacheMedium
  2. 460LFU CacheHard
  3. 895Maximum Frequency StackHard
  4. 1146Snapshot ArrayMedium

Segment tree and Fenwick tree range queries

  1. 307Range Sum Query – MutableMedium
  2. 315Count of Smaller Numbers After SelfHard