Matheus ðŸ‡§ðŸ‡·

Posted on

# How to solve a coding problem

There is a chance that you may have heard that there is no right way how to solve a problem. Every coder has a method, a step-by-step guide on how to find the solution, and this is personal, this is creative freedom.

Not everyone thinks the same, and this isÂ good news. Allowing us to have a different approach for a complex task, and look for the most commons solutions for the repetitive ones.

We can go through some steps to the problem-solving method:

• Understand the problem
• Plan a Solution
• Break into small pieces
• Translate to code.

In the first three steps, you don't need an editor.

Letâ€™s start it.

### Understand the Problem

Every time a code-related problem appears, it seems to rush the anxiety to open your favorite editor as soon as possible. First, you need to understand the problem.

There is nothing wrong to donâ€™t fully understanding the problem at first.

If someone tells you that this is easy, this person isÂ lying.

Now, itâ€™s time to start sketching, simulate inputs, draw arrows for the output. Take notes on what kind of instructions are happening to obtain that result. Let's plan a solution!

### Plan a Solution

The magic word here is pseudocode.

Pseudocode is the bridge between the program and the algorithm.

You can read it better here:Â https://www.unf.edu/~broggio/cop2221/2221pseu.htm

Do you remember your sketch before?

Keep taking notes, but now give a name for your arrows.

Is it conditional? Is this repetitive? Should I loop through it?

There is no perfect plan.

1. Identify all the steps.
2. Identify the parts of the problem.
3. Guide yourself through your logic.

There is a high chance that your solution may change. And trust me, it is not a waste of time.

`trial and error` is part of the process. Trust the process!

If you consider yourself a perfectionist, you may think, why? Why would I even try if there is a high chance it won't work?

Because the simple step of planning gives you the idea of the whole thing, what works, what don't.

Here you are going to use everything you have studied. And it is an opportunity to learn on-demand.

There is no right or wrong here, do in a way you understand and help you.

### Break the Problem into small pieces

There are many coding challenges that can be solved with one instruction. There will be times when youâ€™re going to need the evaluation of one instruction, to go to the next step. Since most of the kinds of stuff that we do in our daily lives we do automatically, we might think that coding is the same thing.

For example, to drink water:

1. Go to the kitchen
2. Open the container that holds the drinking glass
3. Find a drinking glass
4. Pick up the drinking glass
5. Walk to the source of drinking water
6. Put the drinking glass in a position to be filled.
7. Fill the glass with water
8. When the glass is full â‡’ Drink.

Do we think in all of these steps? No.

Each of these steps is linked, you need to complete one instruction to go to the next one. All these processes are known as Algorithms.

Get your sketch again, and divide, break your problem, everything that seems complex, break it. Divide into chunks, solve all those chunks, then you can solve the whole.

Keep it short, and simple.

### Translate to Code

Now you can open your IDE and write your code. There will be times when trying and observing the results is the best way, called Experimentation. However, this works best when you have domain about what youâ€™re doing.

Donâ€™t expect for typing and magically working.

What if you canâ€™t solve the entire problem?

### Practice!

If you got stuck, there is no problem looking for other solutions and how other people solve them. But return to the same problem a while later, and try to do it again.

As I said in the beginning, solving problems is a whole new skill set.

Only by practicing and exposing yourself, over and over, youâ€™ll improve it.