Data Structures & Algorithms practice
Data Structures & Algorithms · Cost & Arrays

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.

Q1What an Array IsEasyMust Do

Contiguous memory, and why data[i] is O(1).

Q2What an Array IsEasy

Array versus the other things you already know.

Q3IndexingEasy

Indexing, negative indexing, and bounds.

Q4Dynamic ArraysEasyMust Do

A Python list is a dynamic array. Watch it grow.

Q5Cost by PositionEasyMust Do

Insert and delete cost depends entirely on WHERE.

Q6TraversalEasy

Five ways to walk an array, and when each is right.

Q7SlicingEasy

Slices copy. Know exactly what that costs.

Q8Building ArraysEasy

Six ways to build a list, compared.

Q9Searching an ArrayEasy

Finding a value: what it costs and what you can do about it.

Q10Modifying In PlaceEasy

Changing an array without building a new one.

Q11ReversalEasyMust Do

Reverse an array in place, and understand the loop bound.

Q12RotationEasy

Rotate an array, the obvious way.

Q13RotationEasyMust Do

Rotate in place with three reversals.

Q14Filling & CopyingEasy

Copying, filling, and the difference between them.

Q152-D ArraysEasyMust Do

Grids, row-major order, and the shared-row trap.

Q16Running ScansEasy

Compute a running value in one pass.

Q17AliasingEasyMust Do

Two names, one array — the bug that looks like magic.

Q18Comparing ArraysEasy

Equality, ordering, and what they cost.

Q19Arrays of RecordsEasy

Arrays holding structured items.

Q20Reading Array CodeEasy

Read ten array operations and state the cost of each.

Q21Fixed vs DynamicEasy

What a fixed-size array would give you, and what Python does instead.

Q22Bounds & Edge CasesEasy

The five inputs that break array code.

Q23Growth StrategiesEasy

Build your own dynamic array and watch the amortisation.

Q24Memory LayoutEasy

What the array actually looks like in memory.

Q25Putting It TogetherEasyMust Do

Choose the array operation that fits the constraint.

Q26Read/Write PointerMediumMust Do

The idiom this whole topic is built on.

Q27Read/Write PointerMedium

Remove duplicates from a sorted array in place.

Q28Read/Write PointerMedium

Move all zeros to the end, keeping the order of everything else.

Q29Read/Write PointerMedium

Filtering with a rule, in place.

Q30Read/Write PointerMediumMust Do

Compact, compress, and count runs.

Q31PartitioningMedium

Split an array into two groups, in place.

Q32Dutch National FlagMedium

Three-way partitioning in one pass.

Q33KadaneMediumMust Do

The maximum subarray sum, in one pass.

Q34RearrangingMedium

Rearranging by position: interleaving, reversing groups, shuffling deterministically.

Q35MergingMedium

Merge two sorted arrays.

Q36CountingMedium

Counting elements without sorting.

Q37Two ArraysMedium

Operations across two arrays.

Q38ReshapingMedium

Flatten, chunk, and reshape.

Q39In-Place ConstraintsMediumMust Do

When the problem says "O(1) extra space", what is left?

Q40VerificationMedium

Test in-place array code properly.

Q41Array as Scratch SpaceMedium

Use the array itself to store extra information.

Q42Reading PositionsMedium

Problems answered by positions, not values.

Q43BoundariesMedium

Off-by-one errors, and how to stop making them.

Q44StabilityMedium

When the relative order of equal items matters.

Q45Choosing an ApproachMediumMust Do

Given the constraint, pick the array technique.

Q46Multiple PassesMedium

When two passes beat one clever pass.

Q47Sorted ArraysMedium

What sortedness buys you, and what it costs.

Q48Memory BehaviourMedium

Measure what array operations really cost in memory.

Q49Common MistakesMedium

Eight array bugs, each shown failing.

Q50Reference CardMediumMust Do

Everything from this band, on one page.

Q51IntervalsMediumMust Do

Merge overlapping intervals.

Q52Sweep LineMedium

Counting overlaps with a sweep.

Q53Majority ElementMedium

Find the value appearing more than half the time, in O(1) space.

Q54Matrix RotationMedium

Rotate a square matrix 90 degrees, in place.

Q55Spiral TraversalMediumMust Do

Walk a matrix in spiral order.

Q56Matrix MarkingMedium

Zero out rows and columns, using the matrix itself as the marker.

Q57In-Place State UpdateMedium

Update every cell simultaneously, in place.

Q58Digit ArraysMedium

Arithmetic on numbers stored as arrays of digits.

Q59Rearranging by RuleMedium

Alternate, group, and reorder by a property.

Q60Choosing In-PlaceMediumMust Do

Five problems, one constraint each — pick the technique.

Q61Consecutive RunsHard

The longest run of consecutive values, in O(n).

Q62Running ProductsHard

Maximum product subarray, and why it needs two running values.

Q63Best Pair in OrderHardMust Do

The best buy/sell pair, where order matters.

Q64In-Place MarkingHard

Find every duplicate and every missing value, in O(1) space.

Q65Two SweepsHard

Problems where each element depends on both sides.

Q66Constrained MaximaHard

Maxima with a distance or ordering constraint.

Q67Rectangular MatricesHard

Transposing and reshaping when the matrix is not square.

Q68Circular IndexingHard

Treating an array as a ring.

Q69Verifying RearrangementsHard

Prove a rearrangement is correct, not just plausible.

Q70Technique SelectionHardMust Do

Ten problems. Name the technique before writing anything.

Q71DebuggingHardMust Do

This in-place function passes its tests and is wrong. Find out why.

Q72Aliasing BugsHard

A grid function that corrupts data it never touched.

Q73Off-by-OneHard

Five broken loops. Find and fix each bound.

Q74Broken InvariantsHard

The write pointer, subtly wrong.

Q75Accidental QuadraticHardMust Do

Array code that is quadratic without a nested loop.

Q76Surprise MutationHard

Functions that modify their arguments without saying so.

Q77Grid BugsHard

Four bugs that only appear on 2-D data.

Q78Lost OrderingHard

A rearrangement that silently discards information.

Q79Numeric PitfallsHard

Arithmetic bugs specific to arrays of numbers.

Q80Reading Array CodeHardMust Do

Ten array functions. State what each does, its cost, and its bug.

Q81Misleading TestsHard

Tests that pass on broken array code.

Q82Memory BlowupHard

Array code whose time is fine and whose memory is not.

Q83Undocumented PreconditionsHard

Functions that work until they silently do not.

Q84End-to-End DebuggingHard

A slow, wrong array function, diagnosed and fixed.

Q85Code ReviewHard

Review an array module and rank what you find.

Q86Mini-Project — Dynamic ArrayMini-ProjectMust Do

Build a dynamic array from a fixed-capacity store.

Q87Mini-Project — Grid EngineMini-Project

A flat-backed 2-D grid with no shared-row trap.

Q88Mini-Project — Ring BufferMini-Project

A fixed-capacity queue with O(1) at both ends.

Q89Mini-Project — Sparse ArrayMini-Project

An array that is mostly empty.

Q90Mini-Project — Matrix ToolkitMini-ProjectMust Do

Matrix operations, built and verified.

Q91Mini-Project — Array DiffMini-Project

Compare two arrays and describe what changed.

Q92Mini-Project — Run-Length CodecMini-Project

Compress and decompress, with the format's limits made explicit.

Q93Mini-Project — Array StatisticsMini-Project

A statistics pass with the numerics done properly.

Q94Mini-Project — Array PlaygroundMini-Project

An instrumented array that reports what an algorithm did to it.

Q95Mini-Project — Test SuiteMini-Project

A reusable test harness for in-place array functions.

Q96Explaining ArraysInterview

Explain why array costs are what they are.

Q97DiagnosingInterview

"The import got slow." Work the problem.

Q98Design Under ConstraintInterview

Design an array-backed structure to meet stated bounds.

Q99Mock InterviewInterview

An array interview, transcribed.

Q100CapstoneInterviewMust Do

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.

Book my free session