← Theory of Problem Solving

How I Solve Problems

How to read an analysis

The problem analyses on this site are designed to guide you through the process of solving the problem. The question they try to answer: how can someone reproduce the thinking that leads to correct solutions? Each analysis is broken into the following sections:

  • Problem Description — written in my own words. This helps me make sure I fully understand what the problem is saying.
  • Initial Observations — immediate ideas that came to mind while reading the problem statement. Reflects the intuition.
  • Idea Sections — each Idea is a single cohesive train of thought: the problem-solving processes used, observations and proofs made, and questions asked. Each Idea ends with its result (Accepted, Wrong Answer, Time-Limit-Exceeded…). An abandoned Idea is recorded too — the false starts are part of the story.
  • Review Section — a concise solution summary reiterating the final correct answer, the key points and observations that unlock it, and ideally the code itself.
  • References — related problems, learning points, and further reading.

The problem-solving techniques

There is no exact science to problem-solving — despite the name “Theory of Problem Solving.” But there are heuristics and mental habits we can consciously apply to maximize our ability to solve problems. Most of these come from How to Solve It (George Polya) and Problem-Solving Through Problems (Loren C. Larson):

  • Draw a Picture. Sometimes seeing an idea with your eyes helps you think about a problem differently.
  • Examine Examples. The sample test-cases — and examples of your own — help you understand how the problem works.
  • Draw from Experience. Try to recall a relevant theorem, algorithm, or similar problem.
  • Problem Transformation. Change the way you think about the problem. Rephrase it using different notation.
  • Problem Simplification. Think of simple or special cases to solve first. Once you solve these, try the real problem.
  • Problem Generalization. Is this problem a special case of a more general problem? Try the larger one instead.
  • Work Backward. The input is A, the answer is B. What if the input was B and the answer A?
  • Write It Out. When formulas are involved, write them down. Avoid errors later — and maybe find a nice pattern.
  • Ask for Help. It is sometimes okay to ask for help, or to look at the solution if you're stuck.
  • Generate and Test. If you have a hunch, try it — and prove that it works later.
  • Exploit the Constraints. Sometimes the input is so constrained that a hard problem becomes easy. Pay attention.

Why write analyses at all?

A mentor once suggested I write analyses of the problems I solved. It became a habit, because the best way to actually learn and improve is not just to solve a lot of problems — it is to go back and think about howyou solved the problem in the first place. In essence: solve it again, but be conscious about the questions you asked yourself and the assumptions and claims you made informally. By formalizing and writing it out, you may find connections you didn't realize were there.

The same approach carries directly into quantum algorithms — a different domain, but the same discipline of reconstructing solutions from first principles.