Arrays & In-Place Techniques: Practice Questions
100 questions. Try each one yourself before checking the answer.
Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.
Contiguous memory, and why data[i] is O(1).
Array versus the other things you already know.
Indexing, negative indexing, and bounds.
A Python list is a dynamic array. Watch it grow.
Insert and delete cost depends entirely on WHERE.
Five ways to walk an array, and when each is right.
Slices copy. Know exactly what that costs.
Six ways to build a list, compared.
Finding a value: what it costs and what you can do about it.
Changing an array without building a new one.
Reverse an array in place, and understand the loop bound.
Rotate an array, the obvious way.
Rotate in place with three reversals.
Copying, filling, and the difference between them.
Grids, row-major order, and the shared-row trap.
Compute a running value in one pass.
Two names, one array — the bug that looks like magic.
Equality, ordering, and what they cost.
Arrays holding structured items.
Read ten array operations and state the cost of each.
What a fixed-size array would give you, and what Python does instead.
The five inputs that break array code.
Build your own dynamic array and watch the amortisation.
What the array actually looks like in memory.
Choose the array operation that fits the constraint.
The idiom this whole topic is built on.
Remove duplicates from a sorted array in place.
Move all zeros to the end, keeping the order of everything else.
Filtering with a rule, in place.
Compact, compress, and count runs.
Split an array into two groups, in place.
Three-way partitioning in one pass.
The maximum subarray sum, in one pass.
Rearranging by position: interleaving, reversing groups, shuffling deterministically.
Merge two sorted arrays.
Counting elements without sorting.
Operations across two arrays.
Flatten, chunk, and reshape.
When the problem says "O(1) extra space", what is left?
Test in-place array code properly.
Use the array itself to store extra information.
Problems answered by positions, not values.
Off-by-one errors, and how to stop making them.
When the relative order of equal items matters.
Given the constraint, pick the array technique.
When two passes beat one clever pass.
What sortedness buys you, and what it costs.
Measure what array operations really cost in memory.
Eight array bugs, each shown failing.
Everything from this band, on one page.
Merge overlapping intervals.
Counting overlaps with a sweep.
Find the value appearing more than half the time, in O(1) space.
Rotate a square matrix 90 degrees, in place.
Walk a matrix in spiral order.
Zero out rows and columns, using the matrix itself as the marker.
Update every cell simultaneously, in place.
Arithmetic on numbers stored as arrays of digits.
Alternate, group, and reorder by a property.
Five problems, one constraint each — pick the technique.
The longest run of consecutive values, in O(n).
Maximum product subarray, and why it needs two running values.
The best buy/sell pair, where order matters.
Find every duplicate and every missing value, in O(1) space.
Problems where each element depends on both sides.
Maxima with a distance or ordering constraint.
Transposing and reshaping when the matrix is not square.
Treating an array as a ring.
Prove a rearrangement is correct, not just plausible.
Ten problems. Name the technique before writing anything.
This in-place function passes its tests and is wrong. Find out why.
A grid function that corrupts data it never touched.
Five broken loops. Find and fix each bound.
The write pointer, subtly wrong.
Array code that is quadratic without a nested loop.
Functions that modify their arguments without saying so.
Four bugs that only appear on 2-D data.
A rearrangement that silently discards information.
Arithmetic bugs specific to arrays of numbers.
Ten array functions. State what each does, its cost, and its bug.
Tests that pass on broken array code.
Array code whose time is fine and whose memory is not.
Functions that work until they silently do not.
A slow, wrong array function, diagnosed and fixed.
Review an array module and rank what you find.
Build a dynamic array from a fixed-capacity store.
A flat-backed 2-D grid with no shared-row trap.
A fixed-capacity queue with O(1) at both ends.
An array that is mostly empty.
Matrix operations, built and verified.
Compare two arrays and describe what changed.
Compress and decompress, with the format's limits made explicit.
A statistics pass with the numerics done properly.
An instrumented array that reports what an algorithm did to it.
A reusable test harness for in-place array functions.
Explain why array costs are what they are.
"The import got slow." Work the problem.
Design an array-backed structure to meet stated bounds.
An array interview, transcribed.
Build one array-backed system that uses everything in this topic.
Stuck? Solve it with a mentor.
Your first 1-on-1 session is free.