Want to Level Up Your Coding? Try a Competitive Coding Challenge!
Programming
Summary
- Competitive coding challenges let you test and reinforce your knowledge in data structures and algorithms.
- Challenges cater to various skill levels and offer benefits like interview preparation and learning how to build more efficient code.
- Tips for beginners include using your preferred IDE, having a base solution, and checking for edge cases.
There are many ways to go from being a beginner coder to someone with a bit of experience. If you don’t have a company where you can intern, one of the most effective ways to level up your coding is through competitive online coding challenges. Let me explain.
What’s a Competitive Coding Challenge, Anyway?
Competitive coding challenges are a series of problems you have to solve in a programming language of your choice as quickly and efficiently as possible. In a coding challenge, you’ll probably run into things you know from the core basics of your learning. For example, we covered data structures in the recipe manager we coded in Rust. Many coding challenges help you learn how to build data structures easily and test your knowledge of coding custom data structures.
One of the best things about coding challenges is that, no matter what your skill level, you can find a challenge that will test your knowledge and reinforce your learning. These challenges also come in a timed variety, giving you the experience of thinking on your feet to solve a problem. You have to determine which of these coding challenges best suits your skill level and knowledge.
What Benefits Are There to Coding Challenges?
Any level of programmer can complete coding challenges. However, what you choose to explore in a coding challenge differs depending on what you want to learn. Among the benefits that you get from exploring coding challenges include:
- Reinforcing Fundamentals: Know a little bit about data types, structures, and basic algorithms but want to learn more? Fundamentals dive into the core of a language and help you cement what you already know about the basics of the language, including conditionals, flow statements, and data structures.
- Interview Prep: If you plan on becoming a programmer, you’ll have to do some practical training before you head into an interview. Technical interviews sometimes ask you to solve programs on the fly, and these coding challenges give applicants a leg-up on the type of questions they’re likely to be asked.
- Competitive Coding: If you like coding for the fun of it and enjoy making things more efficient as a challenge, then coding challenges sometimes reward competitors with good solutions. Prizes can vary, but some programmers make good money coding competitively.
- Building Connections: Nothing unites people like facing similar problems. Many of these competitive coding sites have active communities that help others understand how to solve the problem or propose new and unique ways to solve a well-known problem. They’re a great resource for making friends who love to code as much as you do.
C++, Java, and Python are the most common languages for which coding challenges are offered, and some coding challenge sites specialize in a few of these languages. So, what does the inside of a coding challenge look like? Let’s find out!
Starting and Completing a Coding Challenge
Let’s look at a sample coding challenge. This one from HackerRank focuses on the basics of Python coding. Right off the bat, you can see that there’s a straightforward task listed in the left pane with an embedded compiler in the right pane.
All the way to the left, beyond the pane, are a series of tabs allowing you to check out the submissions for hints or the leaderboard to see who’s submitted for this challenge and succeeded.
Let’s look at this particular coding challenge. We need to figure out if n, the given integer, is odd. If it is, we print out “Weird.” That already gives us a line:
if n % 2 == 1: # Check if n is odd
print("Weird")
That seems fine, but what about the other conditions? Well, we can use an elif statement to check other conditions. The final code I came up with for this is:
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
if n % 2 == 1: # Check if n is odd
print("Weird")
else: # If n is even
if 2 <= n <= 5:
print("Not Weird")
elif 6 <= n <= 20:
print("Weird")
elif n > 20:
print("Not Weird")
In this case, I use elif
throughout the code block to create fall-through statements where the conditions are satisfied. This is a simple challenge focusing on using the if-then-else conditional statement in Python, but some get very involved. The medium-difficulty coding challenges include iterators and even something that helps with Regex commands.
A Few Tips For Doing Coding Challenges
Coding challenges can be fun, and you learn a lot from them, but if you’re a beginner, it may be overwhelming to just jump into a challenge. Here are a few things you should keep in mind when doing these challenges to ease yourself into them:
- Use your own IDE: We covered setting up Visual Studio for Python before, and it’s my preferred IDE, but if you have one that you like better like Rider or VS Code, then code in that and paste it into the challenge document later.
- Have a base solution: Some places may advise you to brute-force a solution—try stuff until something works. I always find the most efficient way of solving things is to have a solution in mind. If that doesn’t work, then go to plan B.
- Check for edge cases: Sites like HackerRank won’t tell you outright what they’re testing for in the test cases. If you don’t handle the potential edge cases, you’ll fail the submission.
- Optimize syntax and data structures: The final thing I’d suggest is to optimize your code syntax and data structures after you’re done with the code. This gets you into the habit of writing efficient code. Consider it extracurricular to coding challenges.
Where Can You Find Coding Challenges?
I already covered HackerRank in the previous challenge, and they’re the one I rely on for my own coding challenges. However, they’re far from the only site you can use. Among the alternatives are:
- FreeCodeCamp: If you’re a beginner and need some help with the basics, this is a great option for novices to get their feet wet.
- Edabit: If you don’t have too much time doing your coding challenges, then these bite-sized challenges can fit into any open space in your schedule.
Coding challenges are great ways to explore what you’ve learned in code using practical examples. If you’re new to coding and want to test yourself, give them a try. You may be surprised at how much you’ve learned since you started!