Lesson 28 of 30
Getting stuck isn't a sign you're not cut out for this. It's the normal, expected middle of almost every real problem — here's what to do about it.
10 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
This topic is about judgment and practical tradeoffs more than a single right answer — a mock interview is the better way to test yourself on it.
Be interviewed on this →Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Picture standing in front of a locked door with a ring of unlabeled keys. You don't just freeze. You try a key, notice it doesn't fit, try another. You keep moving, even without knowing which key works yet.
Getting stuck in a DSA interview feels like that door, except your brain says freezing is safer than trying a key that might be wrong. It isn't. Every engineer — junior, senior, even the person interviewing you — gets stuck regularly. What separates people is having a small set of moves for what to do next, instead of going silent. Here are four:
None of these require already knowing the answer. All four are things you can do the moment your mind goes blank.
// You're asked: "find the length of the longest strictly increasing
// run of numbers in an array." You freeze for a second. Here's what
// getting unstuck sounds like, turned into comments:
// "Let me shrink this. With [1, 2, 1, 3, 4], what's the answer by
// hand? 1,2 is increasing (length 2). Then it drops. 1,3,4 is
// increasing (length 3). So the answer here is 3."
// "I don't see the fast way yet, so let me name the brute force:
// check every starting point, walk forward while it keeps
// increasing, track the longest run I find."
function longestIncreasingRun(nums) {
let longest = 1;
let current = 1;
for (let i = 1; i < nums.length; i++) {
if (nums[i] > nums[i - 1]) {
current++; // run continues, keep growing it
} else {
current = 1; // run broke, restart at this number
}
longest = Math.max(longest, current);
}
return longest;
}
// "Actually — walking through it out loud, I realize I don't need to
// restart from every point. One pass, tracking the current run,
// already gets me the answer." That realization only showed up
// because the small example and the brute-force framing came first.
When step 3 or step 4 of the problem-solving framework stalls out, these four moves are what get you moving again — shrinking the example is literally step 2 of that framework, reused as a rescue tool.