Skip to main content

Thinking Before You Code in Interviews

A repeatable way to avoid writing the wrong solution too early in coding interviews.

Andrews Ribeiro

Andrews Ribeiro

Founder & Engineer

Track

Senior Full Stack Interview Trail

Step 5 / 14

The problem

Many people lose points in interviews before they write the first line.

They hear a familiar keyword, recognize a known pattern, and rush into implementation.

It looks like speed.

Most of the time, it is just anxiety wearing the clothes of confidence.

The risk is simple:

you can solve the wrong problem very well.

This shows up in:

  • coding interviews
  • system design interviews
  • real work discussions

The context changes.

The mental mistake is the same: building too early.

Mental model

Thinking before you code is not wasting time.

It is reducing the chance of investing effort in the wrong direction.

A useful model fits in four steps:

  1. restate the problem in your own words
  2. confirm the constraints and edge cases
  3. propose the simplest baseline that works
  4. optimize only when it is clear why the baseline is not enough

If you want the short version:

First make sure you are solving the right thing. Then improve the right thing.

Breaking it down

Reframe the problem

Before you think about algorithms, repeat the problem back in your own words.

That does two things:

  • it surfaces misunderstandings early
  • it shows that you know how to reduce ambiguity

Close the constraints that change the answer

Not every interview needs a long interrogation.

But some constraints change everything:

  • does original order matter?
  • do I need to preserve the index?
  • can I use extra memory?
  • what input size are we assuming?

Two or three good constraints are usually enough.

Ten questions in a row just turns framing into noise.

If you ignore this too early, your chance of picking the wrong technique goes up fast.

State the smallest correct solution

The baseline is the smallest correct solution you can explain clearly.

It matters because it:

  • anchors correctness
  • reveals the real bottleneck
  • gives context for the next optimization

Optimize for a reason, not by reflex

The jump from baseline to a better version needs a clear reason.

Examples:

  • O(N^2) is already too expensive
  • I need a single pass
  • I need to preserve the original structure
  • I need faster response under higher volume

Without that reason, the answer becomes a bag of tricks.

Simple example

Suppose the prompt is:

Find the first repeated number in a large array.

A rushed answer is to open the editor and type Hash Set immediately.

A better answer sounds like this:

Let me confirm the goal first: we want the first value that appears twice in reading order, right? The simplest baseline is comparing each element with the ones after it using two loops. It is easy to validate, but it costs O(N^2). If the array is actually large, I would trade memory for speed and use a Hash Set to detect repetition in O(N).

In a few sentences, you showed:

  • understanding of the prompt
  • a baseline
  • the cost of that baseline
  • the reason for the pivot

That is usually enough to make the interviewer relax, because they can see where you are going.

The same reasoning works in system design too.

Common mistakes

  • Jumping to the optimized algorithm before validating the problem.
  • Staying quiet because you want to look fast.
  • Ignoring edge cases because you want to get to the “interesting part.”
  • Treating the baseline like wasted time.
  • Spending so long framing the problem that you run out of time to execute.

How a senior thinks

People with more experience rarely look like the fastest person in the first minute.

They look like the most controlled.

Their reasoning usually sounds like this:

I want to make sure I am solving the right thing first. Then I will show the smallest correct version. If that version does not scale, I will improve it knowing exactly what I am trading.

That posture is strong for two reasons:

  • it reduces rework
  • it signals maturity

What the interviewer wants to see

When you think before you code, the interviewer sees more than technique.

They see:

  • your ability to reduce ambiguity
  • your judgment around baseline versus optimization
  • your clarity when explaining trade-offs
  • your discipline under pressure

In interviews, the right solution matters a lot. But the way you get there tells the interviewer how much they can trust you.

Mature candidates do not rush to look fast. They move with more control so they make fewer wrong turns.

Quick summary

What to keep in your head

Practice checklist

Use this when you answer

Next article What Interviewers Look for in Practical Exercises Beyond the Code Previous article What 2026-Style Interviews Are Actually Testing Now

Keep exploring

Related articles