Problem-solving is one of the essential skills required not only in your professional career but also in your personal life. One tool which tremendously helps in effective and efficient problem solving is programming. However, without a formal education in computer science or practical training, it becomes really tough to develop programming skills and solve problems in a structured manner. In this post, I am going to share a simple strategy that will help you to think like a programmer and develop problem-solving skills.

One equation which you must remember to become a great problem-solver is,

Framework + Practise = Problem-solving Skill

That is, you must develop a right framework for solving problems and then practise that framework diligently on as many problems as you can. This is a simple equation but by following this equation consistently, you will definitely develop a mental model for effective problem-solving. Let us talk about the framework first.

Framework

A simple 4-step framework that gives a logical structure to your thoughts and makes problem-solving fun is as follows.

image




1. Understand the problem

The first thing which you must do when approaching a problem is to understand it thoroughly. Understand the inputs and outputs clearly. Ask a lot of questions to identify the scope of the problem and the assumptions you are making. Explain your understanding to your friend or just speak that out to yourself in plain English to clarify your thinking. Doodle a diagram to visualize the problem and the desired solution. Think of an example that perfectly demonstrates the problem. This step is extremely important to develop right thinking. As a byproduct, you will also develop critical thinking skill.

2. Plan the solution

Once you understand the problem throughly and have a clear vision of the expected solution, the next step is to plan the solution. Start with a simple brute-force strategy. Think ‘what can be the easiest way to reach the solution?’ It does not matter if your strategy is not efficient or smart. Your job at this step is to ensure correctness and a logical structure of steps to reach the desired solution.

3. Breakdown into mini-problems

Once you have figured out, what algorithmic steps are needed to reach the correct solution, the next step is to breakdown those steps into sub-problems. Many a times, we feel overwhelmed when a problem is too complex. But once we break down the problem into mini-problems, we realise that it is not that tough and is easily doable, just like a cooking recipe! At this step, you must think how to breakdown a big problem into smaller sub-problems that transform your solution into a step-by-step recipe. This technique is often called ‘reduce the problem’ technique.

4. Implement and debug

Finally, now when you know intuitively how to reach the goal, its time to implement it. Implement your naive approach step-by-step and ensure that it gives the correct output. You will face a lot of errors while you implement but do not give up. The trick is to start loving the errors. An error does not mean that your are a failure but it is an opportunity for you to learn more. Debug your solution one sub-problem at a time to catch the error. Research all your errors on StackExchange or coding platforms, and learn immediately how to solve it. Soon you will find a pattern in your errors and a cumulative improvement in your programming skill. If you are unable to catch the error, re-assess the problem from a different perspective and think ‘where am I going wrong? Which step needs to be corrected or improved?’ and repeat the steps 1-4.

Practise

Selecting the right framework is the first step, but unless your practise that framework on a lot of problems your thinking will not improve. So here I give some tips that you can follow while practising.

image

  1. Go from a simple approach to a complex approach. Remember that thinking naive is thinking right.

  2. First ensure correctness of your solution, then improve efficiency. Here your knowledge of data structures and algorithms will help.

  3. Test the solution with general case and edge cases. Analyse the worst case and the best case performance of your solution.

  4. After your attempt, look at the codes of other people and ask yourself ‘what have they done differently or more efficiently?’

  5. Make sure to comment your code properly. That’s a sign of an efficient programmer.

  6. Keep on learning new algorithms and strategies. It is good to keep a memo of them and practise them often. Always remember, you do not know a tool well until you know where and how to use it.

  7. Create a routine to practise problems. For example, practise 2-3 problems/day.

Resources

Here are some resources to help you get started.

  1. Leetcode
  2. HackerRank
  3. Coderbyte
  4. Data Structures and Algorithms Made Easy

At last, I wish that you enjoy your problem-solving journey and grow every single day. Please let me know your feedback about this article and share other tips that have helped you in becoming a problem-solver!

Happy learning!