Linked-lists

45 articles

dsa8 min read

Remove Zero Sum Consecutive Nodes — Prefix Sum HashMap Explained

Learn how to remove consecutive nodes that sum to zero from a linked list using a prefix sum hashmap in two passes. A tricky interview problem asked at Google and Amazon that combines linked list manipulation with the classic prefix sum technique.

Read →
dsa8 min read

Reverse Linked List II — In-Place Partial Reversal Explained

Master reversing a subrange of a linked list in-place in a single pass. A classic interview problem at Facebook, Microsoft, and Amazon that tests your pointer manipulation skills and ability to handle complex multi-pointer state.

Read →
dsa8 min read

Merge Nodes Between Zeros — In-Place Pointer Walk Explained

Learn how to merge all nodes between consecutive zeros in a linked list into a single sum node in O(n) time and O(1) space. A clean simulation problem from LeetCode 2181 that tests in-place pointer manipulation and linked list traversal confidence.

Read →
dsa8 min read

Reverse Nodes in Even Length Groups — Group Counting Linked List

Learn how to reverse nodes in each even-length group of a linked list by carefully counting group sizes and applying in-place reversal. A moderately tricky interview problem at Amazon and Google that tests group traversal and selective reversal skills.

Read →
dsa8 min read

Linked List Components — HashSet Membership Count Explained

Count the number of connected components in a linked list defined by a given set of values using a single traversal and O(1) HashSet lookups. A clean O(n) interview problem at Google, Amazon, and Bloomberg that tests your ability to convert a graph concept into a simple linear scan.

Read →
dsa8 min read

Reverse Nodes in k-Group — Recursive and Iterative Deep Dive

Master reversing nodes in groups of k in a linked list — the classic hard interview problem asked at Amazon, Google, Facebook, and Microsoft. Learn both the elegant recursive solution and the iterative approach with clear pointer diagrams.

Read →
dsa9 min read

Merge K Sorted Lists — Min-Heap and Divide & Conquer Explained

Master two optimal approaches to merge k sorted linked lists: min-heap for O(n log k) time and divide-and-conquer for O(n log k) with lower constant factors. A top-tier interview problem at Amazon, Google, Facebook, Microsoft, and Uber that tests your mastery of heaps and recursive merging.

Read →
dsa8 min read

Sort List Bottom-Up — O(1) Space Merge Sort on Linked Lists

Master bottom-up merge sort on a linked list for O(n log n) time and O(1) space — eliminating the O(log n) recursive stack. A hard interview problem at Amazon, Google, and Facebook that demonstrates deep understanding of merge sort and linked list mechanics.

Read →
dsa8 min read

Convert Sorted List to BST — O(n) In-Order Construction Explained

Learn the optimal O(n) approach to convert a sorted linked list to a height-balanced BST using in-order construction — consuming list nodes sequentially without finding the midpoint each time. A clever interview technique at Amazon, Google, and Microsoft that demonstrates advanced recursion thinking.

Read →
dsa8 min read

LRU Cache — Doubly Linked List + HashMap from Scratch

Build an LRU Cache from scratch using a doubly linked list with sentinel nodes and a HashMap for O(1) get and put operations. The most frequently asked hard design problem at Amazon, Microsoft, Google, and Facebook — explained step by step with diagrams.

Read →
dsa8 min read

Design Browser History — Doubly Linked List Implementation Explained

Implement a browser history data structure with visit, back, and forward operations using a doubly linked list for O(1) navigation. A practical design interview problem at Amazon, Microsoft, and Google that tests your ability to model real-world state with linked list pointers.

Read →
dsa6 min read

Middle of the Linked List — Fast and Slow Pointer You Must Know Cold

LeetCode 876 Middle of the Linked List teaches the fast/slow pointer technique that appears in half of all linked-list interview problems. Find the middle node in one pass with zero extra space, and understand exactly which middle you get for even-length lists.

Read →
dsa8 min read

Linked List Cycle — Floyd's Tortoise and Hare Explained Step by Step

LC 141 Linked List Cycle is a classic interview question asked by Amazon, Microsoft, and Google that tests your mastery of the two-pointer fast/slow technique. Learn Floyd's tortoise and hare algorithm with a visual dry run, Python and JavaScript solutions, and key interview tips.

Read →
dsa9 min read

Palindrome Linked List — Split, Reverse, Compare in O(1) Space

LC 234 Palindrome Linked List is a popular interview problem at Facebook, Amazon, and Apple that combines three core techniques: fast/slow pointer midpoint finding, in-place list reversal, and two-pointer comparison. Master the O(1) space solution with Python and JavaScript code and a step-by-step dry run.

Read →
dsa7 min read

Remove Duplicates from Sorted List — Single Pass Pointer Walk Explained

LC 83 Remove Duplicates from Sorted List is a foundational linked list interview problem asked at Bloomberg and Microsoft. Learn the single-pass pointer walk solution with Python and JavaScript, a visual dry run, common traps, and how to extend it to the harder variant (LC 82).

Read →
dsa8 min read

Delete Node in a Linked List — The Copy-and-Skip Trick Explained

LC 237 Delete Node in a Linked List is a clever trick problem asked at Adobe and Microsoft that tests whether you understand linked list node deletion when you only have access to the node itself and not the head. Learn the copy-and-skip approach with Python and JavaScript solutions.

Read →
dsa8 min read

Intersection of Two Linked Lists — The Two Pointer Length Equalizer

LC 160 Intersection of Two Linked Lists is a popular O(1) space interview question at Amazon, Facebook, and Microsoft. Learn the elegant two-pointer length-equalizer trick, the mathematical proof behind why it works, visual dry run, and Python/JavaScript solutions.

Read →
dsa8 min read

Remove Linked List Elements — Dummy Head Pattern for Clean Deletion

LC 203 Remove Linked List Elements is a fundamental interview problem asked at Google and Amazon that teaches the dummy head sentinel pattern for handling head deletion cleanly. Learn O(n) solutions in Python and JavaScript with visual dry run, common mistakes, and recursive variant.

Read →
dsa9 min read

Remove Nth Node From End of List — One-Pass Two-Pointer Solution

LC 19 Remove Nth Node From End of List is a classic one-pass interview problem at Amazon, Google, and Facebook that combines the dummy head sentinel with a two-pointer n-gap technique. Learn the optimal O(n) single-pass solution with Python and JavaScript, step-by-step dry run, and common interview traps.

Read →
dsa8 min read

Swap Nodes in Pairs — In-Place Pointer Rewiring Without Swapping Values

LC 24 Swap Nodes in Pairs is a medium linked list interview problem at Microsoft and Bloomberg that tests precise multi-step pointer manipulation. Learn the iterative dummy-head approach and the recursive solution with Python and JavaScript, detailed visual dry run, and interview tips.

Read →
dsa8 min read

Odd Even Linked List — Two-Chain In-Place Grouping Explained

LC 328 Odd Even Linked List is a medium interview problem at Facebook, Amazon, and LinkedIn that tests your ability to maintain two separate pointer chains simultaneously. Learn the O(1) space two-chain pattern with Python and JavaScript, a visual dry run, and interview tips.

Read →
dsa8 min read

Rotate List — Circular Reconnection With Length Normalization

LC 61 Rotate List is a medium interview problem at Amazon and Microsoft that tests your ability to use circular linked list manipulation and modular arithmetic to rotate by k positions efficiently. Learn the optimal O(n) solution with Python and JavaScript, detailed dry run, and the critical k mod n insight.

Read →
dsa8 min read

Reorder List — Split, Reverse, Merge in One Pass

LC 143 Reorder List is a composite interview problem at Facebook, Amazon, and Google that combines three core patterns: fast/slow midpoint finding, in-place second-half reversal, and interleaved merging. Master the O(1) space solution with Python and JavaScript, step-by-step visual trace, and interview approach.

Read →
dsa9 min read

Add Two Numbers — Carry Simulation on Reversed Linked Lists

LC 2 Add Two Numbers is one of the most iconic interview problems at Amazon, Google, and Microsoft where you simulate grade-school addition on two reversed linked lists digit by digit. Master the carry propagation technique with Python and JavaScript solutions, visual dry run, and common pitfalls.

Read →
dsa9 min read

Add Two Numbers II — Stack-Based Reverse-Order Addition Explained

LC 445 Add Two Numbers II is a medium interview problem at Amazon and Google where numbers are stored most-significant-digit first, requiring stacks or list reversal to process from LSB. Learn the optimal stack-based solution with Python and JavaScript, dry run, and the key difference from LC 2.

Read →
dsa8 min read

Partition List — Two Dummy Head Chains for Stable Partitioning

LC 86 Partition List is a medium interview problem at Bloomberg and Amazon that extends the dummy-head two-chain pattern to partition by value comparison. Learn the stable O(n) solution with Python and JavaScript, visual dry run, and critical edge cases including the tail-cycle trap.

Read →
dsa9 min read

Sort List — Merge Sort on a Linked List Step by Step

LC 148 Sort List is a classic O(n log n) interview problem at Amazon, Google, and Facebook that applies merge sort to a linked list using fast/slow pointer splitting and recursive merging. Learn top-down merge sort with Python and JavaScript, a complete dry run, and the bottom-up O(1) space follow-up.

Read →
dsa8 min read

Remove Duplicates from Sorted List II — Delete All Occurrences with Dummy Head

LC 82 Remove Duplicates from Sorted List II is a medium interview problem at Google, Amazon, and Bloomberg where you remove ALL nodes that appear more than once from a sorted list. Learn the dummy-head predecessor skip pattern with Python and JavaScript, step-by-step dry run, and the critical difference from LC 83.

Read →
dsa8 min read

Copy List with Random Pointer — HashMap Clone and O(1) Space Interleave

LC 138 Copy List with Random Pointer is a medium interview problem at Amazon, Microsoft, and Facebook that requires deep-copying a linked list where each node has a random pointer. Learn the O(n) space hash map approach and the clever O(1) space interleave technique with Python and JavaScript solutions and detailed dry run.

Read →
dsa9 min read

Flatten Multilevel Doubly Linked List — Stack-Based DFS Explained

LC 430 Flatten a Multilevel Doubly Linked List is a medium interview problem at Microsoft and Amazon that uses DFS or an explicit stack to inline child sub-lists into the main list. Learn the iterative stack approach and the recursive approach with Python and JavaScript, step-by-step dry run, and interview tips.

Read →
dsa9 min read

Linked List Cycle II — Floyd's Algorithm to Find Where the Cycle Starts

LC 142 Linked List Cycle II is a medium interview problem at Amazon, Microsoft, and Google where you find the exact node where a cycle begins using Floyd's algorithm and a mathematical proof. Learn the two-phase approach with Python and JavaScript, the math proof, visual dry run, and common interview questions.

Read →
dsa10 min read

Find the Duplicate Number — Floyd's Cycle Detection on an Array

LC 287 Find the Duplicate Number is a brilliant medium interview problem at Amazon, Google, and Facebook where you find a duplicate in an n+1 integer array in O(1) space by treating the array as an implicit linked list and applying Floyd's cycle detection algorithm. Master the connection between arrays and linked lists with Python and JavaScript solutions and detailed proof.

Read →