DEV Community

Avi Aryan
Avi Aryan

Posted on • Updated on

Why you should do Competitive Programming, even if a little

cover

First posted on Dev Letters

I first started Competitive Programming (CP) in the first year of undergrad college. I should have started sooner.

CP has played an important role in my career so far. In fact, it was the major reason I got the freelance contract (Toptal) that I am doing. Simply speaking, being good in Competitive or Sports Programming allowed me to outrank other programmers by a large margin.

So yes, CP is important. Let's just list down the reasons why it helps you as a programmer.

(1) Improves Logic

Your logic improves by practice. You weren't this smart to being with. With CP, you continuously train yourself with algorithmic problems that test the better out of your current logic skills. With more and more practice, you get better.

(2) Speeds up coding

This might be a direct consequence of point (1). With an improved logic, you will be able to solve problems faster, decide faster, and put it into code faster, without going to and fro thinking about the best approach to code it.

Bonus benefit - There are many 2-3 hrs contest for Competitive Programming, so if you are in a habit of giving those, you must have increased your typing speed too.

(3) You will start writing the best possible code in every situation

C, C++, and Java are all compiled languages. That is, they interact directly with the system, and by extension, give you 100% control (figuratively) of how your code runs.

If you are doing CP in these languages (which you should), you will regularly run into situations where your code hangs short by a few milliseconds or takes a little too much memory. Micro-optimizations play a huge part then.

  • Is the loop running more times than it should?
  • Can the recursion tree be somehow stunted?
  • Can we make better use of the variables to reduce memory footprint?

Solving these problems helps you write better code in other interpreted languages like Python, Ruby, JavaScript. It won't matter whether you are coding a mobile app or writing a cron task monitor.

The lessons you learn in CP will stay with you, everywhere you code.

(4) And last but not the least, CP helps you crack hiring coding rounds

Coding rounds have always used Competitive Programming as a test of the candidate's potential. I don't 100% agree with it but you can't do anything about it. So practicing CP here will always increase your chances of getting selected.

As I said, I only managed to land a contractor position at Toptal, thanks to my CP skills.

So you should practice Competitive Programming if you don't. There are plenty of good free websites that will help you.

My recommendation would be starting with Hackerrank and then moving to Codeforces and Codechef.


If you liked this article, you might also like the following.

Top comments (18)

Collapse
 
rrampage profile image
Raunak Ramakrishnan

Hi Avi,

I agree with many of your points. Here are my thoughts on the same:

  1. Competitive coding improves one kind of thinking namely that of formulating algorithms where the problem statement is static. Most business tasks are more of getting data from multiple sources, combining them according to domain specific rules and handling various types of failure cases. Competitive programming does not help in this case.
  2. One plus about learning competitive coding is that you learn the standard library of your language very well in order to complete some tasks with minimal fuss. It also makes you dig deeper into the documentation to see why a particular function or structure is slow.
  3. It is one way of improving your perseverance. Coding is all about learning from failure. Trying repeatedly to pass the question hardens you to compile and runtime errors and improves your debugging skills.
  4. On the flip side, you must be careful about writing 1 letter variables and cryptic functions in production because unlike competitive coding where you are the only consumer of your code, your whole team depends on your code.
Collapse
 
aviaryan profile image
Avi Aryan

Agreed! I am not saying Competitive Programming is all you need, but it's something you should have an idea of. Carrying some CP experience into real-world programming helps.

Collapse
 
zeroknight profile image
Alex George

Hey, you're the guy that wrote ClipJump! I just started using it a week ago. What a small world!

Anyway, these are great reasons to do competitive coding, or even more laid-back programming challenges. I really like programming challenges since they're great to do when you have some spare time, and there's tons of them! Here's a short, non-exhaustive list:

  • Advent of Code — Fun Christmas-themed challenges every December. Many of the problems are based on famous math and computer science problems. My first foray into programming challenges, and one of my favorites. Hosted by Eric Wastl.
  • Project Euler — Very math oriented. Haven't yet tried this one, personally
  • Synacor Challenge — Another one by Eric Wastl, quest-oriented like Advent of Code, but delves into things like creating virtual machines and more.
  • Exercism — Variety of programming problems and challenges for a plethora of languages and tools. Check out the tracks page, it's huge!

Programming challenges are great exercises, and are a really fun way to get into a new language and try it out, as you don't have to come up with something non-trivial to work on, and will definitely get you to learn the ins and outs of the language and its standard library.

Collapse
 
aviaryan profile image
Avi Aryan

Hey, you're the guy that wrote ClipJump! I just started using it a week ago. What a small world!

Haha, I am surprised people still find the need to use it, especially when Windows 10 included a similar feature natively.


I have tried Project Euler for some time, and yup, very math-based. I had to look up theorems for some questions. But it's okay since most of the problems are really elemental, that is, they don't require too much theory knowledge, but just that you need to be smart with math.

Collapse
 
imtiaz101325 profile image
Sk Imtiaz Ahmed

I completely disagree with you. I find young coders getting into CP all the time. They are driven by the short term reward cycle that various problem solving sessions have.

"premature optimization is the root of all evil" - Donald Knuth

Writing the kind of code you write in CP is by no means the best possible code. Actual codebase for actual humans should be declarative and simple.

A more wholesome way to learn is to first build your personal portfolio with projects and then moving into open source-- trying to learn from beautiful codebases while trying to contribute yourself.

Collapse
 
albnori10 profile image
Albnor

I think you should add a part on how to get started with competitive programming also :) great post btw

Collapse
 
aviaryan profile image
Avi Aryan

Stay tuned. I will do that post in a couple of days. 😄

Collapse
 
aviaryan profile image
Avi Aryan
Collapse
 
juanfrank77 profile image
Juan F Gonzalez

I'm actually going to do this next week, going for the second year with some buddies to the IEEEXtreme competition. 24 hours of straight problem solving with code.

Collapse
 
aviaryan profile image
Avi Aryan

wow, best of luck. 😄

Collapse
 
juanfrank77 profile image
Juan F Gonzalez

Thanks mate!

Collapse
 
mayurvpatil profile image
Mayur Patil

Agreed.. I started with battle of bot on HackerEarth platform. competition was so much fun to ctraye bot which plays game for you. it increases problem solving and also intrest towards coding.

Collapse
 
varoman profile image
varo manukyan

Nice article, I totally agree. Have tried this one?
app.codesignal.com/

Collapse
 
aviaryan profile image
Avi Aryan

Yeah, big fan of CodeFights. Didn't knew they changed their name. The 1-on-1 fights are a great way to kill your time, very addictive.

Collapse
 
gregorys100 profile image
Gregory Sequeira • Edited

Shoutout to Code Wars ! I think they have a good collection of problems and a good structure of problems to start with.

Collapse
 
aviaryan profile image
Avi Aryan

The website looks sick. Will give it a try someday.

Collapse
 
yashdeora profile image
YASH PAL • Edited

here is the guide that you should follow to become a competitive programmer.
programmingoneonone.com/2020/05/ho...

Collapse
 
ritikbarnwal profile image
Ritik Barnwal

Nice article, I totally agree. Have tried this one?
extrahacking.com/