Skip to content
technique

In-Place Mutation

Algorithms whose central requirement or advantage is transforming an input structure in place while preserving required data, ordering, reachability, or region invariants.

Tagged articles

In-Place Mutation articles

24 articles in this tag.

Close-up of a digital interface showcasing futuristic graphs and data analytics in low light.
beginner
8 min read

Merge Sorted Array

A left-to-right merge can overwrite values in nums1 before you have compared them. The reliable Merge Sorted Array solution uses backward two pointers:…

View solution
Group of high school students focused on learning in a computer lab setting.
beginner
10 min read

Merge Two Sorted Lists

The common failure mode here is treating linked lists like arrays: copy the values, sort them, and rebuild. That throws away the structure the problem…

View solution
Black computer cables splayed on a vibrant yellow surface, highlighting technology connection themes.
advanced
11 min read

Next Permutation

The reliable way to solve Next Permutation is to stop thinking in four memorized steps. Read the suffix, identify where it is already maximal, then make…

View solution
Close-up of a moss-covered tree trunk in a dark, moody forest setting.
intermediate
10 min read

Partition List

A linked-list partition fails in one of two ways: it loses the unread suffix, or it preserves a stale link and creates the wrong structure. The reliable…

View solution
Modern minimalist workspace with a laptop, ceramic mug, and glass water bottle on a white surface.
beginner
9 min read

Pascal's Triangle II

The requested output is one row, not the entire triangle. Build that row with one working list, and update it from right to left so each calculation still…

View solution
Detailed view of a sewing machine needle stitching fabric, highlighting sewing process and textile technology.
advanced
12 min read

Recover Binary Search Tree

A binary search tree has a structural invariant that is more useful than its parent-child relationships: inorder traversal visits values in sorted order.…

View solution
Professional business meeting with presentation and data analytics on whiteboard.
beginner
8 min read

Remove Element

The array is not shortened. The judge inspects only a prefix, so the job is to compact the values you keep into that prefix and return its length.

View solution
Silhouette of a person walking on a vast sand dune in the desert at sunset in Huacachina, Peru.
intermediate
12 min read

Reverse Linked List II

A localized reversal fails at the boundaries: the middle looks correct, but the prefix disappears, the suffix becomes unreachable, or the returned head is…

View solution
From above of green leaves on thin branches of plant growing in botanical garden
intermediate
10 min read

Rotate Image

The hard part of rotating a matrix is not visualizing the turn. It is moving every value without destroying one that has not moved yet.

View solution
Factory chimneys emitting smoke over rooftops on a clear day, illustrating urban pollution.
intermediate
11 min read

Rotate List

A right rotation looks repetitive when described one node at a time. The useful implementation is one split, one reconnection, and one cut.

View solution
Close-up of a tablet displaying analytics charts on a wooden office desk, alongside a smartphone and coffee cup.
intermediate
12 min read

Set Matrix Zeroes

The dangerous part is not writing zeroes. It is remembering which zeroes were causes and which zeroes were created by your own writes.

View solution
Aerial photograph of a tractor working in a vast, vibrant green field captured from above.
intermediate
11 min read

Sort Colors

The trap in the Sort Colors solution is assuming that “only three values” makes the problem trivial. Counting works. The interview version asks you to see…

View solution
System with various wires managing access to centralized resource of server in data center
expert
14 min read

Sudoku Solver

The phrase “try digits and backtrack” is the easy part. The interview-grade solution keeps four representations synchronized: the board, row constraints,…

View solution
A serene beach with soft sand, gentle waves, and lush green trees. Perfect for a nature escape.
intermediate
11 min read

Swap Nodes in Pairs

A value swap can produce the right sequence while violating the contract. The real task is to move node identities by changing links—and to do it without…

View solution