What must survive reversal?

A(4)→B(4)→C(9) are three existing objects.

Would allocating [9,4,4] satisfy a request to reverse these nodes?

After changing A.Next, what still reaches B?

1 / 12

Linked List Cycle — predict before coding

Pointer identity describes topology; equal values do not create a cycle. Two speeds exploit a deterministic next-pointer graph without allocating a visited set.

Decision: Can an acyclic list whose node values are [7,7,7] be declared cyclic by value equality?

2 / 12

Linked List Cycle II — predict before coding

The first meeting locates a point in the cycle, not necessarily its entrance. A second equal-speed phase uses the modular distance accumulated by Floyd's traversal.

Decision: For a list 0→1→2→3→4→2, which node must be returned, even if the first meeting is elsewhere?

3 / 12

Add Two Numbers — predict before coding

Reverse digit order makes ordinary column addition streamable. The carry is the only information that must pass from one digit position to the next.

Decision: What reverse-order digit list results from [9,9] plus [1]?

4 / 12

Merge Two Sorted Lists — predict before coding

The next smallest remaining value must be one of the two heads. Splicing existing nodes avoids allocating a second list while a dummy head removes the first-node special case.

Decision: When the two current heads both hold 2, does selecting either invalidate sortedness?

5 / 12

Copy List with Random Pointer — predict before coding

Deep copying requires preserving relationships, not just values. A map from original identity to clone identity lets forward and backward random links be connected after all clones exist.

Decision: If two original nodes point Random to the same third node, should the clone contain one or two copies of that target?

6 / 12

Reverse Linked List — predict before coding

Reversal consumes the original forward chain while constructing a backward chain. Saving the next pointer is what prevents a destructive write from losing the unread suffix.

Decision: Why must next be saved before assigning cur.Next=prev?

7 / 12

Reverse Linked List II — predict before coding

An anchor before the segment lets repeated head insertion reverse only the selected region. The original first segment node becomes its stable tail.

Decision: For 1→2→3→4→5 with left=2 and right=4, which node becomes the tail of the reversed segment?

8 / 12

Reverse Nodes in k-Group — predict before coding

Checking group size before rewiring is essential: an incomplete final group is not a smaller reversal problem, because its original order must be preserved.

Decision: What does reversing groups of 3 do to 1→2→3→4→5?

9 / 12

Remove Nth Node From End of List — predict before coding

A fixed pointer gap turns an end-relative rank into a predecessor location. The dummy head makes removing the actual head an ordinary link update.

Decision: For a three-node list, which node is removed when n=3, and why is a dummy useful?

10 / 12

LRU Cache — predict before coding

The map answers where a key lives; the doubly linked list answers which key is oldest. Neither structure alone provides both constant-time lookup and recency updates.

Decision: At capacity 2, after Put(1,10), Put(2,20), Get(1), Put(3,30), which key is evicted?

11 / 12

An access-ordered playlist

A playlist must find a song by ID, move a played song to the front, and discard the oldest when full.

Why does a hash map plus a singly linked list still leave an O(n) operation? Derive the missing state.

12 / 12
←/→ or click edges to navigate · ? help · N notes · F fullscreen