How to Use Sample Coding Problems

The way most people study/prepare with coding problems isn't conducive. The average person will go on a site like AlgoDaily or Leetcode, and will look at a problem for 30 seconds to a few minutes.

Often they'll then jump to the solution after getting stuck, read the solution, and call it a day. If this sounds familiar, don't sweat it.

Trying to memorize the solution doesn't really work. Here's a more effective way, and it's why AlgoDaily was designed the way it was:

0. First, choose a cadence. One interview challenge a day seems to be the ideal amount. If you do 2 or 3 a day in the manner described, you'll be spending 3-4 hours doing it, which is quite ambitious unless you have all day to spend.

It's also mentally tiring, and you likely won't derive a whole lot of marginal benefits past the 3rd or 4th problem. At a certain point, you'll probably begin to eagerly jump towards obvious solutions, which causes you not to understand where your strengths and weaknesses are.

The below process nudges your thought process towards retaining the patterns, and eventually will help you solve problems you've never seen prior.

  1. Commit to about 20-30 minutes of trying to solve it by yourself before going to the solution. Really try to get some semblance of a correct output. Brute force it if you have to - just try to reason about any kind of working solution, no matter how slow the code will run. It will help you get the necessary foundation to optimize later.

  2. If you get stuck, start by look at a single hint. Then keep trying to solve it. Repeat until there are no more hints.

  3. No hints? Start going through the walkthrough or solution very slowly. As soon as you get unstuck, STOP READING, and try to solve it on your own again.

  4. Use the bit of insight to start trying to code again.

Anytime you get stuck again, repeat step 1. Even though you’ve read a part of the solution, the vast majority of learning comes from the struggle of thinking through it yourself. That is what will help you retain it for next time.

Here's some additional steps that really made the difference in my prep:

  1. Write the solution again in another programming language. This forces you to think through the abstractions again, and helps with retention.

  2. Save the problem, and revisit in increasingly long spurts. So you might do it again in 2 days, then revisit in a week, then a month.

Some questions to ask at each step:

  • What have I learned thus far? Is there anything I should know for next time?
  • What pattern or technique did the solution derive from?
  • What hint did I need? How far was I from solving it myself?
  • If asked this same question tomorrow, can I readily solve it without any assistance?
How To Use Sample Coding Problems