Skip to content

00 How To Problem Solve

Jagdeep Singh edited this page Jun 19, 2019 · 1 revision

How to Solve Programming Problems

Allocate your time wisely! Act like each hour is worth $1,000.

Steps:

  1. Read the problem until you understand the problem entirely.
  2. Divide the problem into easier sub-problems, make sure you get to the root of each problem.
  3. Solve each sub-problem.
  4. Refactor your solution for each sub-problem.
  5. Connect the dots between the sub-problems to create a full solution.
  6. Test your solution on all cases you can think of.
  7. Refactor solution and test again.
  8. Once you have a working solution, look for other solutions and compare. Learn from the other solutions to make yours even better.

Reading Notes:

A common mistake programmers make when given a programming problem is improper allocation of time.

Don't rush into coding!

Take the time to understand the problem completely before attempting to solve it. Also, don't try to get the perfect solution right away, get a basic working solution first.

Steps:

  1. Read the problem completely twice. § Read until you completely understand the problem.
  2. Solve the problem manually § Programming is automation plain and simple. The manual process is the foundation of any code you write. § Solve the problem with at least 3 different inputs to make sure you really understand your solution and that it will work for more than one case. § Make sure to look for corner cases and edge cases and do any examples for those kind of cases you can think of.
  3. Optimize the manual steps. § Any easier way to solve the problem. § Are there steps that can be cut/simplified.
  4. Write the manual steps as comments or pseudo-code.
  5. Replace the comments or pseudo-code with real code.
  6. Optimize the real code.

70% of out time should be spent in steps 1-3

Don't waste time on pointless, low-quality activities that don't help towards your true goal/mission.

Value your time. Don't give away your time to unproductive ways that leave you broke, unhappy, and stuck.

Imagine that an hour of your time is worth $1,000. What would your life look like? What people would you stop putting up with? What problems would you stop wasting time on? What things would you stop -- and start -- doing?

Don't be busy, be focused!

"Demonstrating computational thinking or the ability to break down large, complex problems is just as valuable (if not more so) than the baseline technical skills required for a job" - HackerRank

  1. Understand the problem completely. If you can't explain it in simple terms, you don't understand it.
  2. Plan out your solution. Do not dive in without a plan.
  3. Divide the problem into sub-problems and solve each one of those. Once solved, connect the dots.
  4. Stuck? Debug, Reassess, Research.

When approaching a problem, make sure to get to the root cause of why the problem exists and work on how to solve the steps that lead to the root.

Clone this wiki locally