I only had eighteen minutes left, and I knew I'd fail.
I thought I was prepared, but as the interview came to an end, it dawned on me that I had no idea how to solve coding problems.
None of the tutorials I had taken while learning to code had included a method for solving coding problems.
My career as a developer depended on it, so I had to figure out a way to solve problems.
I started researching methods right away. And I discovered one. In fact, what I discovered was a priceless strategy. It was a tried-and-true four-step process that had slipped under the developer's radar.
In this article, I'll go over a four-step problem-solving method that you can use to start solving coding problems confidently.
Solving coding problems isn't just a part of the developer job interview process; it's what a developer does all day. After all, writing code is a problem-solving activity.
A problem-solving strategy
Let us now look at how the various techniques listed below can be used to solve coding problems.
The problem-solving method consists of four steps:
- Recognize the issue.
- Make a strategy.
- Execute the plan.
- Take a look back.
Let's begin with the first step.
Step 1: Recognize the issue.
It's tempting to jump right into coding when given a coding problem in an interview. This is difficult to avoid, especially if you are on a time crunch.
Try, however, to resist this urge. Before you begin to solve a problem, make sure you truly understand it.
Examine the issue carefully. If you're in an interview, you could read the problem aloud to help you slow down.
This is an important first step because we frequently do not take the time to fully understand the problem. You'll have a much more difficult time solving a problem if you don't fully understand it.
2. Make a plan to solve the problem.
Create a strategy for resolving the issue. As you develop a strategy, write it down in pseudo-code.
Pseudo-code is a plain-language description of an algorithm's steps. In other words, your pseudo-code is a step-by-step plan for resolving the issue.
Make a list of the steps you'll need to take to solve the problem. More steps would be required for a more complicated problem.
Professor Evans suggests that for more complex problems, "consider systematically how a human solves the problem." That is, for a moment, forget about how your code might solve the problem and consider how you would solve it as a human. This can assist you in seeing the steps more clearly.
3. Put the plan into action (Fix the problem!)
The problem should be solved as the next step in the problem-solving strategy. Write out your actual code while keeping your pseudocode as a guide.
Professor Evans recommends concentrating on a straightforward mechanical solution. The simpler and easier your solution, the more likely it is that you will be able to program it correctly.
What if you are unable to solve the entire problem? What if you still don't know how to solve a part of it?
Colt Steele offers sound advice here: if you can't solve a part of the problem, ignore the difficult part. Instead, concentrate on everything else that you can start writing about.
Ignore the difficult part of the problem that you don't understand for the time being and write out the other parts. Return to the more difficult part once this is completed.
This allows you to complete at least some of the problem. When you return to the problem, you'll often realize how to approach the more difficult part of it.
Step 4: Take a look back at what you've done.
Once your solution is operational, take the time to evaluate it and determine how to improve it. This could be the time to refactor your solution to make it more efficient.
Here are some questions Colt Steele suggests you ask yourself as you examine your work to determine how you can improve your solution:
- Can you arrive at a different conclusion? What other viable approaches are there?
- Can you grasp it at a glance? Is this correct?
- Can you apply the outcome or method to another problem?
- Can you make your solution perform better?
- Can you think of any other refactoring options?
- How have other people dealt with this issue?
Step 4 may leave you with the impression that your problem will never be solved. Even the best developers occasionally write code that they later wish to change. These are some guiding questions that may be useful to you.
If you have time left in an interview, you can go through this step and improve your solution. Take the time to go over these steps if you are coding on your own.
When I'm doing my own coding, I almost always look at solutions that are more elegant or effective than what I've come up with.
Final Thoughts
We've gone over the four-step problem-solving strategy for coding problems in this post.
Let's go over them again:
The first step is to comprehend the issue.
Step 2: Make a step-by-step plan for resolving it.
Step 3: Put the plan into action and write the actual code.
Step 4: Take a step back and consider refactoring your solution if it could be improved.
Practicing this problem-solving method has greatly aided me in both technical interviews and my current position as a developer.
If you lack confidence in solving coding problems, remember that problem-solving is a skill that anyone can improve with time and practice.
Best wishes!
If you have any comments or questions about this post, please tweet them to me at @excceedd .
Top comments (0)