Linked Lists — Complete Guide: All Patterns & Problem Index
Master every linked list pattern: reverse, two pointers, cycle detection, merge, clone, and design problems — with templates and full index of 45 problems.
webcoderspeed.com
49 articles
Master every linked list pattern: reverse, two pointers, cycle detection, merge, clone, and design problems — with templates and full index of 45 problems.
Reverse a singly linked list iteratively with three-pointer technique and recursively with call stack.
Find the middle node of a linked list in one pass using the slow/fast pointer technique.
Detect a cycle in a linked list in O(1) space using Floyd's two-pointer tortoise and hare algorithm.
Merge two sorted linked lists into one sorted list using a dummy head node to simplify pointer management.
Check if a linked list is a palindrome by finding the middle, reversing the second half, then comparing.
Remove duplicate nodes from a sorted linked list in O(n) with a single pointer walk.
Delete a node given only access to that node by copying the next node value and skipping the next node.
Find the intersection node of two linked lists in O(n) O(1) by switching pointers at the end of each list.
Convert a linked list representing a binary number to its integer value using left-shift accumulation.
Remove all nodes with a given value from a linked list using a dummy head to handle edge cases cleanly.
Remove the nth node from the end in one pass using two pointers offset by n steps and a dummy head.
Swap every two adjacent nodes in a linked list without modifying node values using pointer rewiring.
Group all odd-indexed nodes before even-indexed nodes in O(n) time and O(1) space using two pointer chains.
Rotate a linked list to the right by k places by finding length, computing effective rotation, and rewiring.
Reorder a linked list into L0→Ln→L1→Ln-1 pattern by splitting at middle, reversing second half, then merging.
Add two numbers represented as reversed linked lists by simulating digit addition with carry propagation.
Add two numbers given in forward order by pushing digits to stacks, then building the result list in reverse.
Partition a linked list around value x into less-than and greater-than-or-equal chains, then join them.
Sort a linked list in O(n log n) time and O(log n) space using top-down merge sort with fast/slow split.
Remove all nodes that have duplicate numbers from a sorted linked list using a dummy head and skip logic.
Deep copy a linked list with random pointers using either a hash map or the O(1) space interleave technique.
Flatten a multilevel doubly linked list by inserting child sub-lists inline using DFS or an explicit stack.
Find the node where a cycle begins using Floyd's algorithm: detect meeting point, then reset one pointer to head.
Find the duplicate in an array of n+1 integers in O(1) space by treating indices as a linked list with Floyd's cycle detection.
Find the next greater value for each node in a linked list using a monotonic decreasing stack of indices.
Implement a doubly linked list with sentinel head and tail nodes for clean O(1) insertions and deletions.
Swap the kth node from the front with the kth node from the end by finding both with two pointers.
Remove consecutive nodes that sum to zero by tracking prefix sums in a map and relinking past zero-sum runs.
Split a linked list into k consecutive parts as evenly as possible, front parts get the extra nodes.
Reverse the portion of a linked list between positions left and right in one pass using careful pointer manipulation.
Find the maximum sum of twin nodes (node i + node n-1-i) by reversing the second half and comparing pairs.
Merge all nodes between 0s into a single node with their sum, modifying the list in-place.
Delete the middle node of a linked list using a prev-pointer variant of the fast/slow technique.
Reverse nodes in each even-length group of a linked list by counting group sizes and selectively reversing.
Insert a value into a sorted circular linked list by finding the correct position with careful edge case handling.
Count the number of connected components of a linked list that consist of nodes in a given set.
Flatten a binary tree in-place into a linked list following pre-order using the Morris traversal approach.
Convert a sorted linked list to a height-balanced BST by repeatedly finding the middle node as root.
Reverse every k nodes of a linked list recursively: check k nodes exist, reverse them, recurse on the rest.
Merge k sorted linked lists into one sorted list using a min-heap for O(n log k) time complexity.
Sort a linked list in O(n log n) time and O(1) space using bottom-up merge sort with doubling sublist sizes.
Build a balanced BST from a sorted list in O(n) by counting nodes, building in-order, and consuming list nodes.
Implement LRU Cache from scratch using a doubly linked list with sentinel nodes and a hash map for O(1) operations.
Design a browser history with visit, back, and forward operations using a doubly linked list for O(1) navigation.
Complete cheatsheet for Linked Lists: all 7 patterns, template code, Big O reference, and MAANG interview priority guide.
Merge k sorted linked lists into one sorted list using a min-heap. O(n log k) time by always extracting the current minimum across all list heads.
Implement an LRU (Least Recently Used) cache with O(1) get and put using a doubly linked list and hashmap. Full 5-language solutions.
Implement an LFU cache with O(1) get and put. Uses two hashmaps and per-frequency doubly linked lists to track access frequency and recency simultaneously.