What I Learned Solving A Leetcode Problem A Day For 45 Straight Days
Tags: codequality, leetcode, todayilearned, techtalks
Published: 2021-06-19 00:44:23

<p>
Being an engineer there are so many problems that I have to solve every day that you get into the flow pretty easily. But at work you are mostly solving the same type of problems on a daily basis that you forget that there are other exciting types of problems out there that require you to think differently. A great starting place is Leetcode or any other daily coding puzzle website. Let’s go over how to get started and best practices!
</p>

{% youtube GgWBIgwfr7Q %}

<p>
<h2>The Fundamentals of Solving Coding Puzzles</h2>
</p>
<p>
I think Leetcode does a great job of having daily puzzles that come out in their “Monthly Challenges”. Each month the problems start easy or medium, and progressively get harder. You have 24 hours to submit your solution for credit, after that you can still do the problem just not for any Leetcode Coins. 
</p>
<p>
Step one is to read the problem and understand the example solutions that they give you. Work through the examples on paper if you have to, break down each problem into a series of steps to work toward the solution. Start thinking about potential edge cases that aren’t considered that your design needs to take into account. 
</p>
<p>
Step two is to write some abbreviated pseudo code. I tend to think about this step like the high-level whiteboard coding interview. Run through the algorithm you are going to use to solve the problem. Write down any data structures that you might need and contemplate the time and space complexity. This is the easiest step to fix, but when I get stuck this is the work I refer back to to help get me back on track.
</p>
<p>
Step three is to code your test cases. Now that you have a good idea of what you need to do, write some additional tests and write your test cases in code if you are coding outside of their editor. Leetcode won’t tell you what tests failed outside of the ones they give you (maybe they do if you have premium? Not sure tbh)
</p>
<p>
<strong>Pro tip: Code in your editor. Not in the browser.</strong>
</p>
<p>
Step four is to code and iterate on your design. Just because it passes all the tests doesn’t mean it’s perfect. Think of potential optimizations or ways to make your code more flexible.
</p>
<p>
Step five is to look at what other people did and see if there is anything you can learn from their approach to the problem. There are often multiple solutions so don’t be surprised if you see something slightly different.
</p>
<p>
<h2>Consistency is Key</h2>
</p>
<p>
This might not be surprising, but the more problems you solve the better you get. That’s just how it is. Leetcode does a good job of giving you only the information you need to solve a problem and the more of these types of problems you do, the more you begin to get comfortable with understanding the prompt and planning your approach. The hope is that by doing these exercises often you will continue to grow in your programming skills so that when you have to approach a different type of problem at work, you can draw on any number of examples. 
</p>
<p>

<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xo8009jalzfc6h2vzyaz.png" width="" alt="alt_text" title="image_tooltip"> 
 

</p>
<p>
Thanks for reading this and <a href="https://twitter.com/maurerpwer">tweet me</a> if you have any questions!
</p>