How to Get Started with Competitive Programming

June 20, 2020

Whether you are a high schooler, a university student, or a careered developer, this is the perfect time to start with competitive programming. Yeah, you heard it right! Competitive programming does not have age-barrier or portfolio limitations. It only requires a passionate spirit with some love for coding.

A Complete Roadmap

In general, most hiring programs for software engineers include a technical interview component. These interviews usually consist of coding rounds which require a solid understanding of data structures & algorithms. Since these are the core parts of competitive programming, participating in these competitions can serve as great preparation for technical interviews.

This blog post is geared towards those who have ever thought about or tried to start competitive programming but moved on before seeing it through. Let’s dig into competitive programming by answering all the Why(s), What(s) & How(s)!

What is Competitive Programming?

As Wikipedia says, competitive programming is a mind sport usually held over the Internet or a local network, involving participants trying to program according to provided specifications.

In other words, it is a type of contest where a number of programmers attempt to solve programming questions in a limited amount of time. You can write your solution in any programming language that you’re comfortable with, and your solutions are judged by online judges. Solutions should pass all of the test cases (given and hidden) in order to be accepted under certain time and space limits.

A lot of big tech companies, like Facebook and Google, hire through competitive programming competitions. As an added bonus, various online competitions offer some amazing prizes for the winners.

Benefits of Competitive Programming

Crack the Coding Interviews

Often in coding interviews, companies will present modified versions of easy and medium-level questions from competitive coding. Participating in competitions provides familiarity and confidence in coding interviews to get a leg up on internships and job offers from reputable companies.

Problem Solving Skills

One of the real benefits of competitive coding comes when we start solving problems on our own. During the contest, you will be given some real-word problems that need to be solved in the best possible way in a limited amount of time. This increases our analytical thinking abilities and improves logic building, which translates to developing key skills required to build real-life products.

Strengthen your Software Practices

Competitive programming helps us to build up logic thinking skills, write clean code, better understand the functions and modules, analyze and interpret several alternatives and features, and finally, bring meaningful insight to software products.

Land a Position in your Dream Company

Various companies like Google, Facebook, Amazon, etc. conduct online coding competitions where they directly hire candidates based on their performance in the competition.

Working as a Team

Most coding competitions happen in groups of 2-4 people. Coding alongside different individuals with diverse background and experience levels can be a great way to learn and gain different perspectives. It also encourages strengthening of coordination and management skills, which are often the key to acing coding competitions.

How do I get started? Is there a roadmap or a guide?

Pick a suitable programming language

You can do competitive programming in any programming language – C/C++, Java, and Python are highly recommended. Learn about all the syntaxes, built-in functions, templates, snippets, and library functions such as STL in C++, Big Integers in Java, etc. Working with the fundamentals will bring long term benefit to any individual.

Choose a powerful code editor

You will be working to solve many problems. To increase the speed and efficiency of your work, it is recommended that you write your code in a code editor. VS Code, Sublime Text 3, Pharm & Vim are some of the popular editors where you can use their cool features and practice your craft. Use STL, snippets, and templates whenever you can; it not only saves your code length but also decreases the time to write your code. Now you can focus mainly on solving the actual logic of the problems.

Choose a few platforms to practice and start participating in contests

There are many platforms to choose from:

I recommend for beginners to start with Hackerrank. It has a good set of problems placed in a well-defined manner according to the tags & difficulty levels and undoubtedly has the best user interface & IDE.

For references around data structures and algorithms, consider GeeksforGeeks and original documentation like CPPreference.

After solving a sufficient amount of problems and feeling more comfortable, jump into the actual game arena (i.e. Codeforces, Codechef). Practice as many problems as you can. When you get stuck on some problems, go check out the contest’s editorials and discussion forums.

Learn basic data structures and algorithm concepts

Nearly every coding problem will require the use of a specific data structure or algorithm for an optimal solution. Knowing basic data structures and algorithmic techniques before you start is a must; data structures and algorithms help make programs more efficient. Having a good amount of knowledge in DSA will help you in selecting the optimal data structure for any problem and implementing it with the most optimal logic.

Geeksforgeeks is a great one-stop destination for data structures and algorithm concepts. It has a wide variety of articles on various data structures & trivial and non-trivial algorithms.

Solving different problems

Repeatedly solving similar problems is not going to benefit you in the long run. It will keep you in the wrong bubble. Instead, start solving sufficiently different problems until you master that concept diligently and then jump to another one. Also, it can sometimes help to try to solve the problem initially by hand with pen and paper. This will give you the right foundation and proper roadmap to deliver optimized and bug-free code.

How to Approach Solving Problems

Problem statement

Always give yourself enough time to read the problem statement, carefully. Don’t be in a hurry, when you are reading the problem because this may result in the wrong interpretation of the problem and as a result of this, you will write the wrong code.

Remember, 40% of the problem is already solved by merely understanding the statement carefully.

Important points

Break the whole problem into smaller sub-problems that are easier to handle. So, while reading the problem, make a note of important points that you are going to solve.

Constraints

Before writing the code, you should look for the input/output constraints given in the question. This will help you in deciding the time complexity of your code so that you need not change the code again and again if the code is not in accordance with the constraints (then you will get the TLE error).

Input/Output format

Always take input in the given format, and never use your own format. If you are not following it, then you will get the wrong answer instead of having the right code.

Write the code and test

After deciding the time complexity, write the code and first test your code for the sample input. If it passes, then submit your code and test for other test cases. Also, try to dry run the code for boundary/edge cases, this will help in testing your code for hidden test cases.

More details on online competitions

Participate in online coding competitions that happen regularly across various websites. This is the best tool to measure your growing skillset, where you currently stand, and in which areas you need more practice. By rectifying our mistakes & failures, we eventually help ourselves make that long leap to success.

Also, the cherry on top, is that there are also enticing rewards in these competitions for the winners.

As mentioned earlier, various companies like Google, Facebook, Amazon, etc. conduct online coding competitions from which they directly hire candidates based on their performance. Some of the famous competitions are:

Other competitions include:

Here are some additional tools and resources

3 P’s to Success – Practice, Patience, Proceed

  • To master the art of programming, one has to practice and practice really hard. The road to being a really good coder is very difficult, you will undoubtedly face setbacks, highs, and lows. Here, patience is the key to overcoming these challenges.

  • Consult editorials, online references, YouTube tutorials, different approaches for the solution, and read other contestants’ code after the completion of the contest. Keep believing in yourself and eventually, there will come a time when you can proceed to the next stage after successfully solving the phase.

  • There is so much more to tell about the same. I’ll be discussing them in detail in another blog. Remember there is no shortcut for success. The harder the path, the better the fruit will be. Until then, practice, have fun, and learn a lot.


About the author

Aman Saxena

Aman Saxena is pursuing a degree in Computer Science. He has a keen interest in Competitive Programming & Web Development. He is fond of playing Cricket & solving Big-O complexities. When he’s not glued to a computer screen, he is likely exploring the mighty Universe. For any query or a fruitful discussion, you may connect with him on LinkedIn.

This article was contributed by a student member of Section's Engineering Education Program. Please report any errors or innaccuracies to enged@section.io.