I've worked with hundreds of budding engineers and mathematicians. And while every student is unique, everyone I've worked with has at least one thing in common: at some point, they've all been stuck on a problem.
I can relate; I've been stuck many times as well! And while it's easy to tell students to persevere, this kind of general advice is rarely helpful. In this post, I'd like to outline a few concrete strategies to turn to when you're stuck on a problem.
1. Gather Information
If you're stuck, The first thing to do is pinpoint exactly what you're struggling with. Here are some questions you can ask yourself to help narrow things down, especially in the context of a technical interview:
- Do you understand the problem? If not, what questions can you ask to help improve your understanding?
- Do you have an idea about how to proceed? If not, can you get more concrete examples? For example, if you're asked to write a function, can you generate more input / output examples?
- Do you feel overwhelmed? If so, how can you break the problem down into smaller problems that are a bit more manageable?
It's hard to get unstuck if you don't know what's sticking you. So start by trying to identify, as precisely as possible, what's blocking your progress. Intentionally developing your problem solving skills can help with this; we've written extensively about some of these strategies before, feel free to check them out if you're curious!
2. What Won't Work?
Sometimes you'll get stuck because you're missing a key insight or idea about the problem. In such cases, finding a path to the right idea can be challenging; often times, the realization feels less like a gradual process of discovery, and more like a light switch immediately getting turned on.
But there are some strategies that can hopefully help you find that light switch sooner. One approach that I'm fond of is identifying ideas that definitely won't work. After all, as Sherlock Homles once said, "When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth."
Writing down or verbalizing ideas that won't work can help prevent you from fixating on them, and can free you up to consider other ideas. It's also generally easier to come up with bad ideas than good ones, so brainstorming ideas without worrying about their quality can help inertia from setting in. This exercise also helps narrow the universe of possibilities, which may point you in a more fruitful direction.
3. Move to a Different Part of the Problem
If you find that you're fixating on a piece of the problem for too long, it's worth asking yourself whether there are other parts of the problem you could pursue instead. Eventually you'll have to come back to the part that's flummoxing you, but sometimes a figurative breath of fresh air can help.
For example, suppose you're asked to write a function that accepts a list of numbers and returns a count of how many of them are prime numbers. Loosely speaking, I can think of two sub-problems you'll need to solve:
- Figure out how to determine whether a number is prime
- Figure out how to loop over the list of numbers and, for each one, increment a counter if the current number is prime
It's tempting to focus on these problems in order, since the second one requires a solution fo the first one. But if you're struggling with the first problem for too long, it can be helpful to move on to the second, assuming you have a solution for the first. In other words, assuming you've written some sort of helper function called
isPrime, can you use this helper to solve the second problem?
Being able to temporarily move on from what's blocking you can help you move more quickly, and save you from wasting too much time on whatever's got you stuck.
4. Take a Break
If a figurative breath of fresh air won't help, maybe a literal one will. I do some of my best thinking when I'm not in front of a screen. Sometimes the best thing to do is let your subconscious mull over the problem while you do something totally different. Of course, this tip isn't that helpful in an interview setting, but in general, I've found that knowing when to step away is incredibly helpful.
5. Ask for Help
It's easy to get tunnel vision after working on a problem too long, especially if you're completely stuck on a dead end. In these situations, having a fresh set of eyes on a problem can be quite valuable. And even if other people can't help you with the particulars of your problem, sometimes verbalizing what you're stuck on you can stumble into a solution. In programming, this is referred to as rubber duck debugging.
It might seem like asking for help is a no-no in an interview setting, but I'd argue that nothing could be farther from the truth. When I'm interviewing people, I want them to ask me questions, and I want them to be comfortable when they're stuck. When someone freezes up and can't communicate through their frustration, that's a much more troubling sign.
So whether you're in an interview or on the job, don't be shy about asking for help! Of course, when you do, your question should be as precise as possible; this goes back to the first tip above. The more detailed the question, the more likely you are to get the help you need.
This list is by no means intended to be exhaustive. But hopefully there are some ideas in here that will help you out the next time you find yourself stuck on a problem. And if you have any other techniques you've found useful, please let us know!