How to Solve Programming Problems :
A simple set of steps to follow which you can use for any algorithm type programming problem :
-
Read the problem completely twice. This is the single most important step. You may even want to read the problem 3 or 4 times , If you don’t understand the problem, you cannot solve it. Do not worry about wasting time here, because the better you understand the problem, the easier it will be to solve it.
-
Solve the problem manually with 3 sets of sample data. It is very important to solve the problem manually first, so that you know what you are going to automate, otherwise you are just slinging code around. Which while can be fun, will make you look like an idiot in a programming interview and will probably cause you to sweat profusely.
-
Optimize the manual steps. People often don’t realize how valuable this step is. It is much easier to rearrange and reconstruct and idea or algorithm in your head than it is in code. It’s well worth the effort to try and optimize the actual solution or simplify it when it is still in the most easily malleable state. What you want to do here is figure out if there is another way you can solve the problem easier, or if there are some steps you can cut our or simplify.
-
Write the manual steps as comments or pseudo-code.
What we want to do here is capture all the steps we created and now either put them into our editor as comments or write them as psuedo-code that we can translate to real code.
By doing this, we can know exactly what the structure of the code we are going to write is going to look like which makes the job of filling in the actual code later trivial.
-
Replace the comments or pseudo-code with real code.
All we do here is take each comment and convert it into a real line of code.
-
Optimize the real code.
Sometimes this step isn’t necessary, but it’s worth taking a look at your code and figuring out if you can cut out a few lines or do something simpler.
This is also a good place to make sure all your variables are named with long meaningful names. I cannot stress enough how important having good names for your variables and methods is for helping the person evaluating your code to understand what you were trying to do. This is especially important when you make a mistake!
Act like you make $1000/hr
“Living in frenzy is a sign we’ve squandered too much.” -Niklas Goke
In reality, a lot of people are living a frenzied, busy life. They wear their business as a badge of honor, and brag about their full schedules. Frankly, most people prefer the little dopamine boost of checking boxes on a to-do list than actually getting important work done. How do you value your time? Take stock of the things you did this week. How many of them were worthy of $1,000/hour? How many activities were a true waste of time? Value your time at what it deserves to be. The higher the value, the more important and productive work you’ll do — and the less trivial and mindless tasks you’ll get caught in.
How to think like a programmer — lessons in problem solving
Why is this important?
Problem solving is the meta-skill.
We all have problems. Big and small. How we deal with them is sometimes, well…pretty random.
Unless you have a system, this is probably how you “solve” problems (which is what I did when I started coding):
Try a solution. If that doesn’t work, try another one. If that doesn’t work, repeat step 2 until you luck out.
Have a framework
To find the right framework, I followed the advice in Tim Ferriss’ book on learning, “The 4-Hour Chef”.
It led me to interview two really impressive people: C. Jordan Ball (ranked 1st or 2nd out of 65,000+ users on Coderbyte), and V. Anton Spraul (author of the book “Think Like a Programmer: An Introduction to Creative Problem Solving”).
I asked them the same questions, and guess what? Their answers were pretty similar!
Soon, you too will know them.
Sidenote: this doesn’t mean they did everything the same way. Everyone is different. You’ll be different. But if you start with principles we all agree are good, you’ll get a lot further a lot quicker.
So, what should you do when you encounter a new problem?
Here are the steps: Understand Plan Divide Stuck Practice
5 Whys
5 Whys technique (sometimes known as 5Y). This is a simple but powerful tool for cutting quickly through the outward symptoms of a problem to reveal its underlying causes, so that you can deal with it once and for all.
The method is remarkably simple: when a problem occurs, you drill down to its root cause by asking “Why?” five times. Then, when a counter-measure becomes apparent, you follow it through to prevent the issue from recurring.
How to Use the 5 Whys
The model follows a very simple seven-step process:
-
Assemble a Team Gather together people who are familiar with the specifics of the problem, and with the process that you’re trying to fix. Include someone to act as a facilitator , who can keep the team focused on identifying effective counter-measures.
-
Define the Problem If you can, observe the problem in action. Discuss it with your team and write a brief, clear problem statement that you all agree on. For example, “Team A isn’t meeting its response time targets” or “Software release B resulted in too many rollback failures.”
Then, write your statement on a whiteboard or sticky note, leaving enough space around it to add your answers to the repeated question, “Why?”
-
Ask the First “Why?” Ask your team why the problem is occurring. Asking “Why?” sounds simple, but answering it requires serious thought. Search for answers that are grounded in fact: they must be accounts of things that have actually happened, not guesses at what might have happened.
This prevents 5 Whys from becoming just a process of deductive reasoning, which can generate a large number of possible causes and, sometimes, create more confusion as you chase down hypothetical problems.
-
Ask “Why?” Four More Times For each of the answers that you generated in Step 3, ask four further “whys” in succession. Each time, frame the question in response to the answer you’ve just recorded.
-
Know When to Stop You’ll know that you’ve revealed the root cause of the problem when asking “why” produces no more useful responses, and you can go no further. An appropriate counter-measure or process change should then become evident. (As we said earlier, if you’re not sure that you’ve uncovered the real root cause, consider using a more in-depth problem-solving technique like Cause and Effect Analysis , Root Cause Analysis , or FMEA .)
If you identified more than one reason in Step 3, repeat this process for each of the different branches of your analysis until you reach a root cause for each one.
-
Address the Root Cause(s) Now that you’ve identified at least one root cause, you need to discuss and agree on the counter-measures that will prevent the problem from recurring.
-
Monitor Your Measures Keep a close watch on how effectively your counter-measures eliminate or minimize the initial problem. You may need to amend them, or replace them entirely. If this happens, it’s a good idea to repeat the 5 Whys process to ensure that you’ve identified the correct root cause.
The Super Mario Effect:
A Psychological Trick to Help Achieve Success Painlessly
Our current perception of failure is that it’s painful and to be successful, you have to power through the pain. However, Mark’s experiment says that it’s detrimental to see failure in a negative light. Instead, we must see failure as a predecessor to success; a necessity to learn more. And I understand that it’s much easier said than done. But it’s certainly possible. If we’re to trick our brains into thinking that it’s a game not much different than Super Mario, we can begin to embrace failure, learn more, and consequently find more success in life. And oh, all of that without the need for optimism. Isn’t that wonderful?