How to Solve a Coding Problem in Four Steps?
Find Out How to Understand, Create, Execute, and Review
If you’ve ever taken a CS class, this should sound familiar: there is a difficult coding question and 1.5 hrs to solve it but you don’t know where to start.
Developers run into this issue almost everyday when a task includes a complex coding problem and a tense time limit. The big difference, however, is that seasoned developers know very well that a problem like this should be approached with a four-step method.
1. Understand the problem fully
Just like you learned in school, before you start solving the problem, you need to understand it to the best of your ability. For example, you need to create a function that multiplies one number by another and returns a value. Simple, right? As a developer, you need to think of all possible scenarios and elements of the problem to tackle it.
Ask yourself: What are the inputs? Inputs, in other words, are the arguments that your function receives.
It is clear from the problem that the arguments will be two numbers, but your task needs to extend to thinking of examples when there are more than two numbers. What would happen in this case?
You can also consider cases when letter inputs (“a” and “b”) replace the numbers and subsequent impact on the outcomes.
Next, ask yourself: What are the possible outputs? These would stem from the result of the two number inputs.
This may seem like an obvious and quick step but gaining a full comprehension of the coding problem, its inputs, and outputs is a game-changer when it comes to actually solving it.
2. Create a plan
A detailed plan for solving the problem will help you organize the process and focus on getting the results you need. An important nuance: write the plan in pseudocode.
In other words, it’s a simple description of the steps in your algorithm in a casual language you would use for daily conversations. You could say something along the lines of “multiply the first input by the second input using the multiplication operator.”
This is the step in which you don’t have to think of coding so much but rather focus on plain terms and straightforward ways you would break-down the problem-solving process.
3. Execute the plan
Now that you have a pseudocode, you need to convert it into an actual code. This step is solely about actually solving the coding problem.
Of course, things aren’t as simple as they sound so it’s fair to skip certain parts of the problem if you can’t deal with them and go back to solving them later. This approach will potentially save you time and reduce stress levels.
You need to get at least some of the problem finished, and you will eventually figure out how to cope with harder parts.
4. Go back and review
Once you reach the end goal of your problem-solving adventure, it’s safe to go back and review your work. The odds are that there are always better and more efficient ways to approach a coding task, and oftentimes you can only uncover those ways after a thorough review, of course, only if you haven’t reached the deadline yet. Doing reviews will also help you further improve your coding skills, so it’s a win-win!
Next time you run into a challenging coding problem, you should make sure to use time productively and organize the process. The four steps explained in this blogpost are meant to bring you closer to the result you’re striving for.
Understand, create, execute, and review – keep these verbs in mind and act upon them to tackle even the hardest coding tasks as a pro.