What to Do When You Get Stuck in a Coding Interview

Everyone gets stuck in coding interviews, including people who get offers — interviewers often choose problems hard enough that you will. What they're watching is what you do next: whether you go silent and freeze, or work the problem methodically out loud. This guide is a set of concrete steps for doing the second.

Being stuck is part of the test

A coding interview evaluates problem solving and communication, not just whether you reach the optimal answer. A candidate who gets stuck, reasons out loud, takes a hint well and finishes a working solution often scores better than one who silently produces the answer with no explanation. Getting stuck isn't failing. Going silent is closer to it.

First: keep talking

Silence is the most expensive thing in an interview, because the interviewer can't give you credit for reasoning they can't hear. When you're stuck, narrate:

"I'm not seeing the efficient approach yet, so let me think out loud. The brute force would check every pair, which is O(n²). The repeated work is that I keep scanning for the complement, so something with fast lookups might help..."

If you need quiet to think, say so and set a limit: "Can I take thirty seconds to think about this?" Then come back in thirty seconds and say where you got to.

Step 1: go back to the problem

Many stuck moments are really misunderstanding moments.

  • Restate the problem in your own words, and confirm it with the interviewer.
  • Check the inputs. Sorted or not? Duplicates? Negative numbers? Empty input?
  • Check the output. One answer or all of them? Indices or values? Does order matter?

An overlooked detail — "the array is sorted" — is often the whole key to the solution.

Step 2: work an example by hand

Write a small, non-trivial example and solve it manually, slowly, noticing what you do. Your brain often solves the example with the right algorithm before you can name it. Then try a second example that's different — an edge case, or a case where your first idea breaks.

Step 3: get the brute force on the table

If you don't have the optimal solution, state the brute force and its complexity. It shows you understand the problem, gives you something to optimize, and gives you a fallback if time runs out. Then ask: "I can do this in O(n²) by checking all pairs. Should I code that first, or keep looking for something better?" Many interviewers will tell you which they'd prefer.

Step 4: optimize the brute force

Look at the brute force and ask where the waste is. A useful prompt, popularized by Cracking the Coding Interview, is BUD: bottlenecks, unnecessary work, and duplicated work.

  • Bottlenecks: which step dominates? If you sort in O(n log n) and then scan in O(n), optimizing the scan won't help.
  • Unnecessary work: are you computing something you don't need, like every pair when you only need one?
  • Duplicated work: are you recomputing the same thing — the same sum, the same subproblem? That points toward prefix sums, hash maps or dynamic programming.

Step 5: run through the toolbox

When no idea comes, go through the common techniques one by one and ask whether each could apply. Doing this out loud is fine — it shows a systematic approach.

  • Hash map or set: turns "search for X" from O(n) into O(1).
  • Sorting: often makes a problem easier, and enables two pointers, binary search and grouping.
  • Two pointers or sliding window: pairs in a sorted array, or contiguous subarrays and substrings.
  • Binary search: sorted data, or a monotonic question like "is this answer big enough?"
  • Stack: matching pairs, "next greater element," anything undo-like.
  • Heap: the k largest or smallest, or repeatedly taking the minimum or maximum.
  • BFS or DFS: anything that's secretly a graph, grid or tree; BFS for shortest paths in unweighted graphs.
  • Dynamic programming: "count the ways," "minimum cost," or "is it possible," with overlapping subproblems.

The coding interview patterns guide covers each of these with the signals that point to it.

Step 6: let the constraints tell you the complexity

The input size is a strong hint about the complexity the interviewer expects. Assuming roughly 100 million simple operations per second:

Input size nTarget complexityTypical techniques
up to ~10O(n!)Permutations
up to ~20O(2ⁿ)Subsets, bitmasks, backtracking
up to ~500O(n³)Triple loops, interval DP
up to ~5,000O(n²)Nested loops, 2D DP
up to ~1,000,000O(n log n) or O(n)Sorting, heaps, two pointers, hashing
largerO(log n) or O(1)Binary search, math

If n can be 100,000 and your idea is O(n²), it's too slow — look for O(n log n) or O(n). If the interviewer hasn't given constraints, ask: "Roughly how large can the input get?"

Step 7: take hints well

If the interviewer offers a hint, take it and use it immediately. Hints are part of the format; ignoring one costs more than needing it.

  • Acknowledge it and connect it: "Oh — if it's sorted, I can use two pointers instead of the hash map. Let me think about how they'd move."
  • Don't pretend you were about to get there. Just build on it.
  • Ask for one when you've genuinely run out: "I've tried a hash map and sorting, and I'm stuck on how to avoid the nested loop. Could you point me in a direction?" A specific question gets a useful hint and shows what you've already considered.

Stuck while coding or debugging

Being stuck on a bug is different from being stuck on the approach.

  • Trace your code with a small input, line by line, writing down variable values. Don't scan the code and guess.
  • Check the usual suspects: off-by-one loop bounds, wrong initial values, empty input, modifying a collection while iterating over it, integer division.
  • Test the edge cases explicitly: empty, a single element, all duplicates, negative numbers.
  • Don't rewrite in a panic. Most bugs are one line. Find it.

When you're running out of time

If ten minutes remain and you don't have the optimal approach, code the brute force cleanly and correctly, then explain how you'd optimize it. A working O(n²) solution plus a clear explanation of the O(n) idea is better than half of an O(n) solution that doesn't run. Tell the interviewer what you're doing: "Given the time, I'll code the O(n²) version so we have something working, then talk through the optimization."

Practice getting stuck on purpose

This is a skill you can practice. Pick problems slightly above your level, set a timer, and solve them out loud. When you get stuck, work through the steps above instead of opening the solution. Afterward, ask which step would have unblocked you sooner. Over time, getting stuck becomes a familiar part of the process rather than a moment of panic.

RELATED
FAQ

Questions about getting stuck

Is it bad to ask for a hint in a coding interview?

No. Taking a hint well, after showing what you've tried, is normal and expected. Needing several hints for the core idea can affect your score, but it costs far less than staying stuck in silence.

How long should I stay stuck before asking for help?

If you've made no progress for a few minutes despite working examples and stating the brute force, ask a specific question. Interviewers would rather give a hint than watch the clock run out.

Should I code the brute-force solution first?

Usually state it first and ask. Many interviewers want to hear the optimized approach before you start coding, but if time is short or you're stuck, a correct brute force is far better than nothing.

READY · WIN-X64

Check your reasoning on practice problems.

Interview Assistant AI reads the problem and your code on screen, then streams the approach, the complexity and the code — download it and try it on a practice problem.