DEV Community

Cover image for How to solve any programming problem?
Chandra Prakash Tiwari
Chandra Prakash Tiwari

Posted on

How to solve any programming problem?

Solving a problem in programming is not always easy. I was very confident after learning some great frameworks like node, express, react, react-native and much more and created some awesome apps with JavaScript, but one day someone asked me a simple question. And the question was, how can you check a number is palindrome or not(condition you can't convert it into string)?

I tried and failed, again tried and failed. I became exhausted and started learning some basic concepts of programming.

In this article I am going to share 5 steps to solve any problem. So lets start.

1. Understand the Problem:

Before start writing the code you need to understand the problem. Understanding the exact problem can solve your problem more than 30%. You can ask some questions before start writing the code:

  • Can I restate the problem in my own words?
  • What will be the inputs in the problem?
  • What would be the outputs should come from the solution?
  • Would input determine the output?
  • How should I label the important pieces of data that are part of the problem?

2. Explore problem:

After understanding the problem you need to explore the possibilities like:

  • What if there is no input or invalid input?
  • Is any limitations to the output? Try to find the more options to better understand the problem.

3. Break it down:

This is a most important method to solve any problem. You can break down the code into small steps to solve it. Write down the comments in steps, this will help you to be in track of solving the problem without distracting. Suppose, there is time limitation for solving any specific problem, and you are unable to solve it completely, your comments can help to get the good marks in that. Examiner would be able to understand your approach and right approach is the way to solve any problem.

4. Solve and simplify:

After writing the steps, start solving the problem. Try to solve simple steps first and then solve the complex one.

5. Look back and refactor:

After solving the complete problem, look back to your code and try to refactor it. Make it concise and readable. Try to test it at least one time before submitting.

I hope this will help you to get out of any problem easily. :)

Top comments (0)