How to Practice for Code Challenges
Tags: webdev, beginners, career, javascript
Published: 2021-03-01 14:02:06

# Introduction
>You are given coins of different values and a total amount of money *amount*. Write a function to compute the fewest number of coins that you need to make up that amount.

What code should you write to solve this problem? Or, where would you even start? If you haven't run into coding challenges yet, Google, Amazon, and all of the big software companies use questions like the one above to hire all their new engineers.

If you don’t have a solution for this problem yet then you're in good company - neither do 63% of all programmers who try it (according to <a href="https://leetcode.com/problems/coin-change/">Leetcode</a>). 

What's more important, is that you develop a *framework* to approach these problems with, so that you're prepared for whatever they'll throw at you in a technical interview. 

Here's a list of 5 takeaways that will help you crush code challenges for your technical interview:

![Goku trains with lots of push-ups](https://media.giphy.com/media/g37mGHexrv5ug/giphy.gif)

# 1. Use a Timer or Stopwatch
Pick the amount of time that you want to give yourself for one problem, and stick with it. You might solve the problem ahead of schedule, you might not — either way, **it doesn’t matter if you solve the challenge or not.** As soon as your time’s up, stop what you’re doing and move to the next one. I’m serious.

Your goal shouldn’t be a green checkmark or a gold star...leave that pass/fail nonsense in grade school where it belongs. Instead, your goal should be to attain knowledge. How do you do that? By failing and adapting. Over and over again. To accomplish this, you need *exposure* to lots of different kinds of problems. **Quickly.**

Back when I started solving coding challenges, I spent 45 minutes to an hour on each one and I “failed” almost all of them. Now, I’m spending no more than 20 minutes on each, and I’ll solve 50–75% depending on the difficulty. But forget about me, just worry about your own timer and set it wherever you feel comfortable. Over time you’ll find that you shave off a few minutes; the way you’ll get there is by setting daily goals.

# 2. Set Daily Goals
This will help you to focus and to shut out some of life’s distractions. Sure, it sounds simple — and anyone can set a daily goal — the difficult part is completing this goal day after day. We’re looking for **consistency** here. One daily goal, every day, is much better than completing five goals on Monday while failing to do any on Tuesday.

>Compound interest is the eighth wonder of the world. He who understands it, earns it … he who doesn’t … pays it. -Albert Einstein

In this quote, Einstein was referring to the tendency of money to earn more of itself over time. But if you apply the same idea to *your growth of knowledge over time, you will become unstoppable.*

One thing that you might find helpful is that while I’ve noticed that I’m great at taking somebody else’s instructions, but I’m **terrible** at following my own. Luckily, I’ve found a way around this; write your daily goals for tomorrow before you go to bed tonight. Set them on your desk, and forget about them. You’ll wake up in the morning with a clear head, sit in your chair, and notice a to-do list from a very smart, very organized stranger.

Another thing that helps is if you **set a small number of easy-to-achieve goals for yourself.** Motivation is key; you’re much more likely to solve three Leetcode challenges if you plan on solving two than if you dread solving 30.

# 3. Follow a Framework
![1_WQ4lzbAfqWoq4lTLveghHw](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/24zp2rd07d4zfs1l5spb.jpeg) 

Back when I was solving daily code challenges, I would write notes for every problem I tried. The next time I would job search, my goal will be to fill another notebook. I’m sharing this for two reasons. First, because <a href="https://medium.com/@michaelchrupcala/my-first-week-at-lambda-school-2ea6310cd248" >my bootcamp</a> taught me a really simple framework for keeping notes, called “UPER” —

* **Understand**
* **Plan**
* **Execute**
* **Review**

The first two steps should happen **before you write any code**. To accomplish anything, you have to plan how you’ll get there. But before you can even do that, you need to make sure you *understand* what’s being asked of you.

For example, what’s the input type that your function will receive? What will your output be — a string, or maybe a float? Are you missing any crucial information? 

Next, you’ll execute each of the steps in your plan by defining your variables and writing your functions. Then lastly, review how you did! What did you do well, what can you improve, and what were you unsure about?

The second reason I’m sharing this UPER framework with you, is that I truly believe code challenges are one of the best ways to improve your programming chops. Yes, they’re time-consuming and no you don’t have to be as obsessive about them as I was, *but daily code challenges will make you better*. You’ll learn about your programming language, and you’ll build analytical muscles from all those reps in the Leetcode gym. Most importantly, you'll learn creative problem-solving with every challenge you tackle. And after you're hired, you can flex those muscles when you write code daily at your job!

# 4. Step Away
Don’t take my word for it. <a href="https://www.psychologytoday.com/us/blog/prescriptions-life/201901/taking-walk-will-boost-your-creativity-and-problem-solving">Doctors</a> <a href="https://scienceline.org/2014/11/stuck-on-a-problem-take-a-walk/" > keep</a> <a href="https://news.stanford.edu/2014/04/24/walking-vs-sitting-042414/"> finding</a> that our brains are more creative when we take frequent breaks. Fresh air and exercise aren’t just good for your health. When you’re stuck on a problem and you’ve tried everything, focusing on something new can be the best way forward. Geniuses throughout history such as Steve Jobs, Charles Darwin, Albert Einstein, and Tchaikovsky all knew the importance of taking a walk outside. 

A sudden flash of creative insight can come from anywhere, **especially** when you’re outside taking a breath.

![Bob Ross petting a deer and smiling](https://media.giphy.com/media/8OJdqYqN1Nii3UTD6l/giphy.gif)

# 5. Learn from Others
What’s tough about learning a new skill is that there’s so much information you haven’t learned yet that *you don’t even know what you don’t know*. This is because you’re missing the context — researching on your own is hard because you don’t know where to start. You don’t know what is and is not important; Javascript built-in methods? Functional programming concepts? Data structures? How do you filter through the noise?

<a href="https://leetcode.com/problems/two-sum/discuss/?currentPage=1&orderBy=hot&query=" >Leetcode</a> has a nifty feature that lets you read the code that other people already submitted. When I’m solving code challenges, even if I solved the problem I’ll read through other user’s solutions and take notes.

![1_fdh-5b8Yer-g4_RIX6p_oA](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xs0ljnvvx4vqcmu7wevt.png)
 

Just because you solved the problem doesn’t mean that you can’t still improve. There might be a concise way to solve the same challenge in five lines instead of ten. Maybe you could write a more efficient algorithm or one that uses less computing space. This ties back into the “Review” step of the UPER framework. 

Take a peak at somebody else’s code and you’ll be surprised at how much you can learn about your own.

# Conclusion
Hopefully some of this was helpful, but this is just what worked for me! There’s a lot of great advice out there; both <a href="https://www.youtube.com/c/KevinNaughtonJr" > Kevin Naughton Jr. </a> and <a href="https://www.youtube.com/c/NickWhite" >Nick White</a>’s videos were a huge inspiration to me. Just remember, keep iterating and you’ll find what works best for you.

<a href="https://twitter.com/mikechrupcala" >**Follow me on Twitter**</a> for more programming tips, and DM me if you have any questions or if you’d like some advice. Thank you for reading!