Whiteboard freeze — that moment when you’re working through a tricky coding interview problem, and… you have no idea what the next step is. Your mind just goes totally blank. Ugh.
The good news? It happens to the best of us. Here’s how to get back on track.
1. Relax. It’s part of the process.
In a way, getting stuck like this is supposed to happen. If you don’t struggle at all with a question and just breeze right through it, your interviewer might just say “Hm, this candidate’s probably already seen this question before… let’s just throw it out and try another one.” Seriously, I’ve heard several interviewers say they do that!
Here’s why: They want to see you get stuck. Because they want to see what you do when you don’t know the answer. Put another way, your interviewer is more interested in seeing your problem-solving skills than they are in seeing how much you know right now.
So remember that getting stuck doesn’t mean you’re not good enough. It just means you’re in the part of the interview where you’re stuck. That’s supposed to happen — so just dig in!
2. Solve it “by hand.”
Write out a sample input on the whiteboard. (Or, if it’s a phone interview, on your shared code editor). If it’s an array sorting problem, actually write out a list of numbers. If it’s a tree or graph search problem… draw a tree or graph. Make your sample input short-ish. Not so short that it’s an edge case, but not so long that it’ll be too tedious to solve the whole problem.
Then, solve the problem by hand with that sample input. Step by step. Sort the array. Traverse the graph. Notice what steps you’re taking. Think through how to write out those steps as code. And look out for any repeat work you’re doing as you solve the problem. If there’s repeat work, it’s likely there’s an optimization you can make to speed up your algorithm.
3. Throw some data structures at it.
You’d be surprised how often this leads you to a breakthrough.
“I need to keep track of a bunch of stuff, and occasionally grab the thing I put in most recently…” You need a stack!
“I need to store a bunch of relationships between a bunch of things…” You need a graph!
Even if you don’t think your issue is that you should be using a helpful data structure, it just might be. So walk through the main ones real quick, and see if any of them would help:
4. “Un-twist” the problem
Remember: a lot of coding interview problems are intended to take the better part of an hour to solve, so it makes sense that the solution wouldn’t jump out at you immediately. It’s important to keep in mind that mMost of these problems have parts. There’s a simpler version of the problem, and then a twist that makes it a little harder. And then another twist that makes it harder still.
Some interviewers walk you through that process. They ask you the simple version of the problem first, and when you solve that they add the first twist. But some interviewers just throw the already-twisted version of the problem at you all at once. In that situation, you need to come up with your own way of breaking the problem down into steps — so don’t be shy about “un-twisting” the problem a little bit.
For example: Not sure how to find the kth-largest number in an array? Start by thinking about how to find the largest. Then adapt that approach to find the second largest. Then the 10th largest. Then, finally, the kth-largest.
Nothing gets you un-stuck like having some well-exercised neural pathways that are already accustomed to “coding interview thinking.“ After all, it’s a skill like any other. With practice, it gets easier and faster.
Of course, if you’re in the middle of an interview, practice isn’t going to help you anymore. It’s too late. But you’re not in the middle of an interview right now, are you? You’re reading this article. Looks like you have a few minutes to read something online. So go check out some coding interview practice problems — by the time your next interview comes up, you’ll be glad that you did!
Parker Phinney is the CEO of Interview Cake, which makes free guides and online courses on how to pass coding interviews. [api_jobs_widget job_title=”Software Engineer” job_age= “7” limit=”10″]