skip to content

DSA problem-solving strategy

26 roadmaps35 questionsupdated

How I attack a coding problem end to end: a repeatable solving method, reading constraints to plan before coding, curated study plans, deliberate-practice habits, and knowing what each round format expects. Interviewers grade the process as much as the final code, so this meta-skill layer often decides borderline calls.

on this pageshow

guide

overview

~1 min

Problem-solving strategy is the layer of a coding round that sits around the algorithm rather than inside it. Two candidates can reach the same solution and leave with different verdicts, because the interviewer also scores the route: whether you pinned down the task before building anything, whether a correct baseline existed on the board early, whether your plan followed from the limits in the statement, and whether you checked the result instead of announcing it. On borderline calls this process evidence is often what tips the decision. The subject splits into five sections. The [structured solving method](/topics/found-dsa-problem-solving-method) covers the phases of one problem, from clarifying questions through a brute-force baseline to optimizing and verifying. [Constraint-driven planning](/topics/found-dsa-problem-solving-constraints) is about choosing a technique from the wording and limits before writing code. [Study plans](/topics/found-dsa-problem-solving-study-plans) and [deliberate practice](/topics/found-dsa-problem-solving-practice) are about preparation: how curated lists are meant to be used, and how to train under the conditions the round imposes. [Round formats](/topics/found-dsa-problem-solving-round-formats) explains how a whiteboard, a shared editor and a take-home each define a finished answer. Start with the solving method, because the other sections build on it. Questions range from a junior asking why a naive solution is worth saying out loud to a senior deciding what to cut from a time-boxed take-home.

primer

These sections rest on a few ideas. Hold them and most of the questions below read as consequences. ### The process is part of the answer An interviewer cannot grade reasoning they never heard. A stated plan, a named trade-off and a visible check each give them something to credit, even when the final code is incomplete. A silent candidate gives them little to write down, even when the answer arrives. ### Being wrong early is cheap Each phase exists to catch a class of mistake while it still costs minutes. A clarifying question catches a misread task; a hand-traced example catches an undefined output rule; a baseline catches a misunderstanding of what the output even is. The same mistake found after twenty minutes of code usually costs the round. ### A baseline is an asset, not an admission A slow but correct solution shows the task was understood, sets a cost to beat, and leaves something standing if a better idea does not pan out. Optimizing then means naming the gap between that cost and the lowest cost the problem allows, and closing only the part that matters for the stated input size. ### Constraints decide what is admissible Input sizes, memory ceilings and whether the data can be read twice rule approaches in or out before speed is even discussed. A plan that ignores them can be elegant and still unusable. ### Practice has to match the test Solving at leisure with a run button trains a different skill from solving aloud against a clock. Preparation transfers when it covers every pattern category, rebuilds solutions from memory rather than rereading them, and reviews each attempt for the cause of an error rather than the error itself.

Brute-force baseline
The simplest correct solution, stated with its cost before any optimization, so there is something correct to score and a reference to improve on.
Edge case
An input at the boundary of what the statement allows, such as empty, single-element, all-equal or extreme values, where solutions most often break.
Dry run
Tracing a small concrete input through the solution by hand, step by step, to check behaviour without executing anything.
Dominant term
The part of a total cost that grows fastest and so sets the runtime; improving any smaller term changes little that can be measured.
Lower bound
The least work any correct solution to a problem must do, such as reading every input once; it marks how far optimizing can go.
Test oracle
A trusted reference, often the naive solution, used to check a faster version's output on many generated inputs.
Pattern category
A family of problems solved by the same technique, such as sliding window or graph traversal; the unit curated study lists are built around.
Deliberate practice
Practice aimed at a named weakness, done under realistic conditions and followed by review, rather than solving more problems of the kind you already handle.
Recall versus recognition
Producing a solution from nothing versus following one you are shown. Interviews test recall; rereading solutions mostly builds recognition.
Time box
A fixed limit set in advance for a phase or a whole task, used as a checkpoint for when to move on or what to cut.

The five sections split into two halves: what you do during the round, and what you do in the weeks before it. ### Inside the round The [solving method](/topics/found-dsa-problem-solving-method) is the backbone. [Clarifying and working examples](/topics/found-dsa-problem-solving-method-clarify-examples) fixes what the problem is; [the brute-force baseline](/topics/found-dsa-problem-solving-method-brute-force-baseline) fixes a correct answer and its cost; [optimizing and verifying](/topics/found-dsa-problem-solving-method-optimize-verify) closes the gap and proves nothing broke. [Constraint-driven planning](/topics/found-dsa-problem-solving-constraints) happens between the first two phases: once the task is clear, the limits tell you which families of technique are worth trying, which keeps optimization from being a guess. [Round formats](/topics/found-dsa-problem-solving-round-formats) then adjust the method rather than replace it. The phases stay the same; what counts as finished shifts from a defended plan at a whiteboard to running, tested code in an editor, and to scoping and written trade-offs in a take-home. ### Before the round [Study plans](/topics/found-dsa-problem-solving-study-plans) decide what to practice: enough problems per pattern category that the technique becomes recognisable in an unfamiliar problem. [Deliberate practice](/topics/found-dsa-problem-solving-practice) decides how: under a clock, out loud, with a routine for getting unstuck and a review afterwards. Its three sub-sections mirror the round itself. [Timed mocks](/topics/found-dsa-problem-solving-practice-timed-mocks) rehearse the phase budget, [think-aloud and hint recovery](/topics/found-dsa-problem-solving-practice-communication) rehearse the conversation, and [post-solve review](/topics/found-dsa-problem-solving-practice-review) turns each attempt into input for the next. The algorithm sections of the parent [data structures and algorithms](/topics/found-dsa) hub supply the techniques; this hub is about choosing, sequencing and presenting them under time pressure.

  1. Clarify & Work Examples →

    Every later phase depends on solving the right problem, and clarifying questions are the cheapest point at which to find out you have not.

  2. Brute Force First →

    A correct, costed baseline is what the interviewer scores first and what every optimization is measured against.

  3. Constraint-Driven Planning →

    Reading the limits turns optimization from guesswork into choosing among a few admissible technique families.

  4. Optimize & Verify →

    Improving the baseline and then proving the faster version still gives the same answers completes the method.

  5. Think-Aloud & Hint Recovery →

    Narrating decisions and absorbing hints is the skill that separates solving alone from solving with an audience.

  6. Round Formats & Expectations →

    Once the method is solid, learn how each format redefines finished so you spend minutes where they are graded.

  • Starting to code before restating the task and asking about ranges, ordering and empty input; the misread often surfaces only after most of the time is gone.

  • Treating the sample input as a guarantee, for example assuming sorted order or positive values because the example happened to show them.

  • Searching silently for the optimal idea instead of stating a correct baseline first, which leaves the interviewer nothing to credit if time runs out.

  • Optimizing a term that does not dominate the total cost, then claiming a speed-up the runtime will not show.

  • Declaring an optimized version correct because it is faster, without re-tracing the earlier example and the boundary cases through it.

  • Writing new code in the last minutes rather than tracing a small example through what already exists.

  • Measuring preparation by problems completed rather than by whether each pattern category can be re-derived cold a week later.

The same few tensions come up across this hub, and naming the one you are managing is part of what is scored. - **Time spent clarifying versus time left to code.** Questions and hand traces are cheap insurance, but a plan that never commits is its own failure. A phase budget set before the round tells you when the balance has tipped. - **Baseline first versus straight to the target.** Stating the naive version costs a minute and buys a fallback. Skipping it can pay off only when the optimal idea is obvious and you can defend it at once. - **Optimizing versus stopping.** A lower complexity class is worth pursuing only if the stated input size makes the difference matter and the extra complexity can still be verified in the time left. - **Breadth versus depth in a take-home.** A tested core with the cuts written down usually beats a wide submission that nobody can trust. - **Coverage versus volume in preparation.** More problems in familiar categories feel productive; fewer problems spread across every category transfer better to an unseen variant.

A handful of routines recur across the questions below, each usable on problems you have never seen. - **Restate, then probe the edges.** Restate the task in your own terms, then ask about empty, single, tied, extreme and negative inputs before planning. - **Baseline, cost, gap.** State the naive solution, its time and space, the lower bound the problem allows, and whether closing the gap between them matters at the given size. - **Constraint to technique.** Map the input size and memory limit to a complexity class, and the wording ("count the ways", "shortest", "at most k") to a technique family. - **Fork and check in.** When two approaches compete, state both, say where their costs differ, pick one, and confirm before writing. - **The unsticking ladder.** Rework a small example, then a simplified version of the problem, then scan technique families aloud, announcing each step as you move to it. - **Log, cluster, drill.** Record the cause of each practice error, find where they cluster, and target that category until the rate falls.

report an issue with this guide →

questions

page 1 of 2

After reading a problem's constraints, what must your plan state before you write any code?

level: juniorimportance: must knowfreq 78%

answer

  1. the interviewer is grading this step
  2. constraints are more than input size
  3. name the target before naming the tool
  4. time class and space class, both
  5. say what you ruled out and why

basics

~20 s

A usable plan names the constraints that actually bind (input size, memory ceiling, whether data can be re-read), the time and space class you are targeting, the concrete steps and the data you keep, and what you rejected and why.

solid answer

~50 s

The plan is a short written artefact with five lines. First, the binding constraints, read from the statement rather than assumed: how big the input gets, whether a memory ceiling is stated, whether the data arrives as a stream you see once, whether the same input is queried many times. Second, the target class you are aiming at — **in time and in space**, because space is a constraint in its own right, not a footnote. Third, the approach at the level of steps plus exactly what data you keep resident. Fourth, what you ruled out and which constraint killed it. Fifth, the edge cases you will check: empty input, one element, all values equal, the extreme allowed value. Naming a structure is not a plan; a plan is a target plus the route to it.

go deeper

for a junior

Be ready to say your plan out loud before you type: binding constraint, target class in time and space, the steps, and the edge cases. Practise it until it takes under a minute; interviewers notice its absence more than its polish.

for a middle

Explain how each constraint narrows the candidate approaches — a memory ceiling, a single-pass input and a many-queries workload each eliminate different things. Show the space line being derived, including recursion depth and retained keys, not just guessed.

for a senior

Demonstrate that you plan for the constraint that actually binds, and that you write down what you rejected and why. In production terms, an approach that fits the box beats a faster one that does not, and the plan is where that call is recorded.

for a principal

Own the habit at team scale: reviews and design notes should require a stated budget and a rejected-alternatives line, so that later readers can tell an intentional tradeoff from an accident. Be ready to argue what belongs in that template and what is ceremony.

## Why the step exists Between reading a problem statement and typing the first line of code there is a short artefact that separates candidates who pass from candidates who thrash: a written plan. Interviewers grade it directly — most rubrics have a line for "stated an approach before coding" — but its real value is that it converts the statement's constraints into a commitment you can be held to. Without it, the constraints are read once, forgotten, and rediscovered halfway through an implementation that cannot satisfy them. ## The five lines a plan carries **1. The constraints that bind.** Not every number in a statement matters, and the ones that matter are often not sizes. Look for: how large the input can get; whether a memory ceiling is stated; whether the input arrives as a stream that can be read once, or sits in storage you may traverse repeatedly; whether the same input is queried many times (which pays for preprocessing) or once (which does not); whether the input may be modified in place; the range and duplication of the values; and whether the data already carries useful order. **2. The target class, in time and space.** State what you are aiming at before you choose a mechanism — "linear time, constant extra space" or "linearithmic time, linear extra space". Turning a numeric input bound into a class is its own skill and has its own home; the point here is that the plan must *name* a target, because a target is what makes the rest of the plan checkable. Space gets its own words: recursion depth is space, an auxiliary table is space, and a structure that retains one entry per distinct key is space proportional to the number of distinct keys, which is not the same as the number of items. **3. The approach as steps plus retained data.** Two or three lines: what you do in each pass, and what you hold onto between steps. "Keep a running count per category and the best pair seen so far" is a plan. "Use a lookup structure" is not — it names a tool without saying what it holds, what it is keyed by, or how big it gets. **4. What you rejected, and which constraint killed it.** This is the line most candidates skip and the one that buys the most credit. It proves the constraints were read, and it stops the interviewer re-proposing the idea you already considered. Rejection is often not about asymptotics at all: an approach can be perfectly fast and still inadmissible because it needs the whole input resident, or a second pass over data you only see once. **5. How you will check it.** Empty input, a single element, all values equal, the largest permitted value, and the ordering the statement never promised. Naming these in the plan means you write the code with them in mind rather than patching afterwards. ## A worked tiebreak A log-deduplication feature must emit each distinct request line once. Two target classes are viable. Sort the lines and scan for runs of equal neighbours: linearithmic time, but it needs every line resident at once. Or stream the lines and keep a set of the keys already seen: linear expected time, but the set holds one entry per *distinct* key, and the peak resident size is unknown before you run it. If the statement gives a hard memory ceiling and no bound on distinct keys, neither is automatically right — and the plan's job is to say so out loud: "the ceiling forbids holding all lines, so sorting the whole input is out; the seen-set is admissible only if distinct keys are bounded, which the statement does not promise, so I will ask." That sentence is worth more than either implementation. ## The failure mode this aims at The weak answer is "I'd use a hash-based lookup" — a mechanism with no target, no space line and no rejected alternative. Its close cousin is a plan that budgets time only. Both come from the same habit: treating the constraints as flavour text around the interesting part. In real work the same habit produces a feature that passes review and falls over on the first oversized input, because nobody wrote down what "oversized" meant. ## What good looks like out loud Thirty to sixty seconds, spoken before any code: the constraint you consider binding, the class you are targeting in time and space, the steps, the alternative you dropped and why, and the edges you will check. Then you invite correction — "does that match what you had in mind?" — which is cheap before an implementation exists and expensive after.

  • The statement gives no memory limit at all. Does the plan still need a space line?
    Yes. An unstated limit is an unknown, not an infinity. Write down the space your approach actually uses — auxiliary tables, retained keys, recursion depth — and say what it grows with. Then ask what the real budget is. A plan whose space is written down can be re-judged in one sentence when the budget appears; a plan with no space line has to be redesigned.
  • A deduplication feature can sort and scan, or stream and keep seen keys. The box has a hard memory ceiling. What does the plan say?
    It names the ceiling as the binding constraint, then states what each candidate needs resident: sorting needs every line at once; the seen-set needs one entry per distinct key. It commits to the class that fits the ceiling under the stated bounds, and records the assumption the other option would have needed. The explicit "this is what the ceiling rules out" line is the deliverable.
  • How is a plan different from restating the problem in your own words?
    Restating confirms you read the input and output; a plan commits to a route. Restatement carries no target class, no retained data, no rejected alternative and no edge list, so nothing in it can be wrong yet. Do both — restate in one sentence to check understanding, then plan — but do not let the restatement stand in for the plan.

It is the difference between a route and a vehicle. "I'll take the car" answers nothing; "two hours, one fuel stop, avoiding the toll bridge because the load is over its limit" is a plan somebody can check before you leave.

saying these in an interview costs you the question

  • Names a data structure and calls that a plan
  • Budgets time only, never states space
  • Treats an unstated limit as unlimited
  • Starts coding and works the approach out mid-typing
  • Ignores that the input arrives as a stream
  • Never says which alternative was rejected

context

open as a page

Why state a brute-force solution aloud before optimizing in a coding interview?

level: juniorimportance: must knowfreq 80%

basics

~20 s

A stated brute force proves you understood the problem, gives the interviewer a correct baseline to score, and becomes your fallback if the clever idea collapses. Silence while hunting for the optimal answer reads as being stuck.

open as a page

Why restate the problem and probe edge cases before writing any code in an interview?

level: juniorimportance: must knowfreq 78%

basics

~20 s

Clarifying is the cheapest place to be wrong. A couple of minutes spent restating the task and asking about empty input, single elements, duplicates and negative values beats thirty minutes spent solving the wrong problem.

open as a page

A report recomputes a day's running total from scratch on every query - how do you optimize it, and what do you pay?

level: juniorimportance: must knowfreq 72%

basics

~20 s

Compute the totals once and answer each query by lookup: q queries over n rows drop from O(q*n) to one O(n) pass plus O(1) per query. You pay extra memory, and staleness whenever the underlying rows change.

open as a page

In a coding interview, how do you narrate a fork between two approaches before writing code?

level: juniorimportance: must knowfreq 75%

basics

~20 s

State each approach in a sentence or two, name the cost that separates them, say which one you would take and why, then ask the interviewer to confirm before you write a line of code.

open as a page

Why review a coding problem you already solved and got accepted?

level: juniorimportance: must knowfreq 55%

basics

~20 s

An accepted solution proves your approach worked, not that it was the best one available. Reviewing it surfaces the idea you never had - a better pattern, a lower complexity class - which is what practice is meant to add.

open as a page

How should you budget the phases of a 40-minute coding interview, and why set the split beforehand?

level: juniorimportance: must knowfreq 62%

basics

~20 s

Roughly 5 minutes clarifying, 10 planning, 20 coding, 5 tracing in a 40-minute slot. Fixing the split in advance gives you checkpoints, so you notice time slipping at minute 15 instead of discovering at minute 35 that it is gone.

open as a page

What does done mean differently in a whiteboard round versus a shared-editor round?

level: juniorimportance: must knowfreq 55%

basics

~20 s

At a whiteboard, done means a defended plan: correct approach, stated invariant, complexity, and edge cases named out loud. In a shared editor, done means code that actually runs on the cases you named, including the ugly ones.

open as a page

On a curated interview list, why does pattern-category coverage beat raw problem count?

level: juniorimportance: must knowfreq 45%

basics

~20 s

Interviews hand you an unseen variant, not a problem you have already done. What transfers is the pattern category, so covering every category with fewer problems beats grinding many problems from a handful of categories.

open as a page

What time and space cost do you state for a brute force with two nested loops and an inner scan?

level: middleimportance: must knowfreq 70%

basics

~10 s

Multiply the work, do not count the loops: O(n^2) index pairs times an inner scan of up to O(n) comparisons gives O(n^3) worst-case time. The scan compares in place, so auxiliary space is O(1).

open as a page

The sample feed looks sorted by timestamp — why still ask whether ordering is guaranteed?

level: middleimportance: must knowfreq 62%

basics

~20 s

An example is a sample, not a contract. Sensors buffer and flush late, so a feed that happened to arrive in order once can arrive scrambled tomorrow. Ask, and treat the answer as a fact that changes the plan.

open as a page

You optimized a daily-totals pass and it runs faster - how do you verify it is still correct?

level: middleimportance: must knowfreq 64%

basics

~10 s

Re-run the exact example you hand-traced earlier through the optimized version step by step, checking every transition: first row, last row, a day change, a day with no rows. Faster is not correct.

open as a page

An interviewer offers a hint mid-solve — how do you take it, and what does resisting it signal?

level: middleimportance: must knowfreq 65%

basics

~20 s

Treat a hint as new data, not a verdict. Say it back in your own words, state what it changes about your plan and what it costs, then adjust visibly. Resisting one signals you will argue with review feedback.

open as a page

In a timed coding interview with five minutes left and untested code, do you write more or trace?

level: seniorimportance: must knowfreq 58%

basics

~20 s

Stop writing new code and trace a small concrete example through what already exists. A partial solution whose boundaries you checked yourself reads far better than an untested complete one that the interviewer has to debug for you.

open as a page

"Count the number of ways to fill a rota" — what must your written plan name before you code?

level: middleimportance: should knowfreq 55%

basics

~20 s

A counting statement points at a table-filling plan, and that plan names four things: what one entry counts, how an entry is built from smaller ones, the base cases, and a fill order that computes dependencies first.

open as a page

After stating an O(n^2) baseline, how do you answer the follow-up 'what gap are you trying to close'?

level: middleimportance: should knowfreq 55%

basics

~20 s

Name a defensible target: reading every record floors you at linear, and a comparison-based full ordering at n log n. State the gap from your quadratic baseline to that floor, then whether the real input size makes closing it worth anything.

open as a page

Before coding, why hand-trace a 3-element input with tied readings and a 1-element input?

level: middleimportance: should knowfreq 52%

basics

~20 s

Tiny traces test the problem statement, not just the code. A tie exposes an output rule nobody stated — first match, last, or all of them — and a one-element or empty input exposes whether the output is defined at all.

open as a page

You shaved a log factor off a report's ordering phase but wall time barely moved - why?

level: middleimportance: should knowfreq 55%

basics

~20 s

Total cost is a sum of terms, and the ordering phase was not the dominant one. A quadratic pairing pass still sets the runtime, so removing a log factor from a smaller term changes nothing measurable.

open as a page

What kind of think-aloud narration can an interviewer actually score, and what is just noise?

level: middleimportance: should knowfreq 55%

basics

~20 s

Decisions are scoreable; keystrokes are not. Narrate the choices, the reasons behind them, the assumptions you are making and the risks you accept. Reading your own code aloud or voicing every passing thought produces volume without signal.

open as a page

Your practice error log over 40 problems shows boundary mistakes clustering in grid problems - what do you change?

level: middleimportance: should knowfreq 42%

basics

~20 s

A cluster is a diagnosis, not a diary entry. Take the category with the largest share, drill problems chosen specifically to provoke it, then re-read the tally two weeks later to see whether the rate fell.

open as a page

Why does understanding an editorial solution not count as having learned it?

level: middleimportance: should knowfreq 45%

basics

~20 s

Following a written solution is recognition; producing one later with nothing in front of you is recall, and only recall is what an interview measures. Read the approach paragraph, close it, and rebuild the solution from your own brute force.

open as a page

On a whiteboard with someone watching, what breaks first compared with solo untimed practice?

level: middleimportance: should knowfreq 46%

basics

~20 s

Verification breaks first. With no run button you discover you had been checking correctness by executing rather than reasoning, and the audience plus the missing undo then eat the working memory you were using to hold the plan.

open as a page

Why does a shared-editor round penalize a hand-waved step that a whiteboard accepts?

level: middleimportance: should knowfreq 40%

basics

~20 s

The medium changes what an unverified claim costs. At a board nobody can run anything, so intent is the deliverable; in a live editor an elided step reads as a check you chose not to make.

open as a page

Within one pattern category, why sequence easy-then-medium instead of hopping categories daily?

level: middleimportance: should knowfreq 38%

basics

~20 s

Consecutive problems in one category let you see the same technique under different dressing, which is what turns a solution into a reusable pattern. Daily category hopping gives variety but each problem stays an isolated fact.

open as a page

Your plan for a packet stream under a hard memory ceiling is single-pass; how do you defend it against "just sort it"?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Argue admissibility before speed: sorting needs the whole stream resident, and the stream has no known length and a hard ceiling, so that plan cannot run regardless of its time class. Then name what a single pass gives up.

open as a page

For a payroll adjustment task in integer cents, why ask about amount ranges and signs upfront?

level: seniorimportance: should knowfreq 44%

basics

~20 s

Range and sign are design inputs, not trivia. Totals in cents across a large payroll can outgrow a fixed-width 32-bit signed accumulator, and negative adjustments invalidate any shortcut that assumes a total only grows. Both are cheap questions and expensive bugs.

open as a page

Why sort unmatched refund records first when every scan you replace is only linear?

level: seniorimportance: should knowfreq 48%

basics

~20 s

Sorting is paid once and changes what every later step costs: equal keys become adjacent, so repeated matching collapses into one sweep or a logarithmic probe. It pays when you would otherwise rescan many times, and loses on a one-shot query.

open as a page

What ordered unsticking drill do you run aloud when an approach stalls mid-interview?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Run a rehearsed ladder out loud: re-work a small concrete example by hand, then solve a deliberately simplified version, then scan known technique families aloud and say why each fits or fails. Announce which rung you are on.

open as a page

What belongs in a take-home README, and why does a reviewer open it first?

level: seniorimportance: should knowfreq 35%

basics

~20 s

The README is the tradeoff record, not install instructions. It should state how to run everything, the approach chosen and what it was chosen over, what was deliberately cut and why, known limitations, and what a production version would add.

open as a page

A take-home caps you at four hours: how do you decide what to cut?

level: seniorimportance: should knowfreq 50%

basics

~20 s

Treat the cap as part of the specification. Ship a correct, tested core path and cut breadth: extra features, configurability, and speculative structure. A scoped eighty percent with the cuts stated beats an unfinished attempt at everything.

open as a page

showing 1–30 of 35