How to solve coding problems

How do you break it down enough to where you know that you need to store a variable as an array or as a number in order to be able to solve the problem?

Couple things/approaches: 1) practice, 2) break down big problems into small problems, 3) research the answers (i.e. Google, Stack Overflow, or official docs), and 4) approach analytically and methodically.

Mainly, though, practice. Often, once you’ve found a way to solve a problem, you’re very likely to remember the solution the next time you encounter it.

1 Like

This is kind of the heart of programming: breaking one big problem into many, many, smaller, more manageable, problems.

An array vs number should be straight forward at a high level: do you need to consider one thing or many things?

More abstractly; does the data grow. You might look at (x,y,z) and think array, but if it’s a 3D point it might have more meaning as named variables.

Insight into problems comes from doing lots, and lots, of problems. There will never be a single, best, answer. Rather, there will be the answer that makes the most sense to you at a given moment. Play at it long enough and you’ll probably find your early solutions no longer look as good as they first did. That’s normal.

I often think of this quote when programming: “Art is never finished, only abandoned.” – Leonardo da Vinci

You’ll always see other ways of doing things. At some point, you’ll accept that it works and tweaking it further probably won’t offer much improvement. If you have a nagging feeling you could do it better: good! Never loose that. But also don’t let it discourage you.

2 Likes

Pseudocode (writing out step by step details on how you think you can solve the problem) without writing any code helps tremendously.
Then as mentioned above:

Making that decision will become easier over time.

Also, especially while learning, don’t be afraid to not create the best, most efficient solution.
Rumour has it I once looped through the alphabet in an if else because I hadn’t wrapped my head around a for loop yet… I understood the code though… and it worked!

1 Like