DEV Community

Cover image for How to Practice for Code Challenges
Michael Chrupcala
Michael Chrupcala

Posted on

How to Practice for Code Challenges

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 Leetcode).

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

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

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 my bootcamp 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. Doctors keep finding 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

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?

Leetcode 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

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 Kevin Naughton Jr. and Nick White’s videos were a huge inspiration to me. Just remember, keep iterating and you’ll find what works best for you.

Follow me on Twitter for more programming tips, and DM me if you have any questions or if you’d like some advice. Thank you for reading!

Top comments (11)

Collapse
 
jcyber101 profile image
_jcyber

This was absolutely helpful for me as a young engineer. I’ve been struggling with finding a solution to help improve myself daily when it comes to solving complex issues. I didn’t create an account on leet and I also have an account on codewars as well. The UPER method seems a legit way to get started for me so thank you for sharing. I have my notebook and I’ll definitely follow the steps I should do daily when trying to solve these coding challenges. Great post!

Collapse
 
mikechrupcala profile image
Michael Chrupcala

Oh awesome that makes me so happy to hear that! Thanks a lot I'm glad it helped- tbh I should write a follow-up all about UPER and how I solve one challenge in-depth. Does that sound like a post that would help you out?

Collapse
 
andreagon profile image
Andrea Gonzales

Hi, thanks for writing this! I've been going on and off when it comes to solving coding challenges as I'm struggling with my confidence whenever I fail to find a solution 😅 This helped me realize that learning is more important, and that I will improve if I'm consistent. Will surely follow the advices and steps stated in this post!

Collapse
 
mikechrupcala profile image
Michael Chrupcala

I totally feel that, they're pretty intimidating at first. But the more time you spend with them (pass or no), the faster you'll level-up in experience & confidence. Good luck!

Collapse
 
andrewbaisden profile image
Andrew Baisden

Very useful info, repetition and practice is the way to improve.

Collapse
 
king11 profile image
Lakshya Singh

When I saw that 63% I knew I have to solve it in one go :)

Collapse
 
mikechrupcala profile image
Michael Chrupcala

Niiiiiice!

Collapse
 
aalphaindia profile image
Pawan Pawar

Well Explained!

Collapse
 
phoohtoo profile image
Htoo Aung

Very helpful.

Collapse
 
dougaws profile image
Doug

Is there ANY evidence that leet code crammers make better developers? I thought not.

Collapse
 
yohanchoidev profile image
YC John

I'm not sure if it will help me to be a better programmer. But at least, it helps me to get a job. I guess other people do for the same reason mostly.