Linked Lists Pattern Hub
7 problemsLinked List Cycle
easyFloyd’s Tortoise & Hare: advance `slow` by 1 and `fast` by 2. Inside a cycle of length C, their relative gap decreases by 1 per step, guaranteeing collision inside <= C iterations.
LRU Cache
mediumCombine a HashMap (`key -> Node`) for O(1) lookup with an insertion/recency doubly-linked list (with dummy `head`/`tail` sentinels) so promotion to MRU and eviction from LRU both run in O(1).
Merge k Sorted Lists
hardEither push the head of each non-empty list into a size-k min-heap (`O(N log k)` time, `O(k)` space) OR pairwise divide-and-conquer merge halves (`O(N log k)` time, `O(1)` extra heap allocations).
Merge Two Sorted Lists
easyAnchor the output with a `dummy` sentinel node and a `tail` pointer. Repeatedly attach the smaller of `l1` and `l2`, then splice whichever tail remains non-null in O(1).
Remove Nth Node From End of List
mediumAttach a `dummy` before `head`. Advance `right` `n + 1` steps ahead of `left = dummy`, or advance `right` `n` steps then step both until `right.next == null` so `left` lands cleanly on the predecessor.
Reorder List
mediumThree O(1)-space primitives composed in sequence: (1) find middle via fast/slow pointers, (2) split (`slow.next = None`) and reverse the second half, (3) zipper-merge the two halves alternatingly.
Reverse Linked List
easyMaintain `prev = None` and `curr = head`. Before reversing `curr.next = prev`, save `nxt = curr.next`, then advance `prev, curr = curr, nxt`. Return `prev`.