Skip to main content

Command Palette

Search for a command to run...

How to get started with Competitive Programming?

Updated
4 min read
How to get started with Competitive Programming?

What is Competitive Programming?

Before I tell you how to start CP (Competitive Coding), let me tell you what it is all about. In CP, programmers compete with others to solve coding problems within a limited time taking all the time and space constraints into account and passing all the given test cases.

Why practice Competitive Programming?

As you rack your brains to find the best optimal solution that satisfies all the test cases, you sharpen your logical and analytical skills. With every code you write, your optimization game keeps getting better. This will give you an edge over the other applicants in any coding interview as you are accustomed to finding the best solution for any problem under time pressure.

How to get started?

1. Learn any Object-Oriented Programming Language

To start with CP, pick any object-oriented programming language (preferably C++, Java or Python) and get thorough with its basics - the syntax, loops, conditional statements, operators, arrays and some necessary built-in functions. Once you have familiarised yourself with all of these, you're good to go.

2. Choose any online platform

Now, it is necessary to practice problems and participate in online contests to keep a constant check on your progress. Codechef, Codeforces and HackerRank are some coding platforms you can begin your CP journey with.
You can start by solving easy questions by searching practice problems by their difficulty rating.

3. Learn about Time Complexity and Space Complexity

In CP, knowing about time and space complexity is important as almost in every question, the time limit to run on all test cases is 1-2 seconds and the space limit is 50000 bytes (approx .05 MB) on Codechef and 64-256 MB on Codeforces. Hence, your code has to perform the necessary operations in the least number of lines of code possible.

4. Understanding the Problem Statement and the Input/Output format

Look at this Codechef problem carefully. It has 4 important sections:

i. Problem Statement:

Problem Statement.png Make sure you take some time and read the problem statement carefully. Sometimes the problem statement can be lengthy, so you may want to note down the necessary points.

ii. Input/Output format:

I/O format.png Unlike the normal input method, where we generally provide inputs one at a time, in CP problems, the entire test case is provided as the input at one go. So, keep the input and output format in mind and write the code accordingly.

iii. Constraints:

Screenshot (458).png In a problem, there will always be a few variables mentioned. Under the constraints section, the range of the values across all the test cases (both public and private) for each variable is mentioned.

Here, the value of N ranges from 2 to 50, so we assign the Integer data type.
However, if N would have ranged from 2 to 1010, we would have to assign the Long integer data type.

iv. Sample Cases:

Screenshot (459).png The sample cases tell you what the input and output of the program will look like if it is unclear from the problem statement. Sometimes, it also gives away any loophole in the problem statement which you can make use of to write a simple solution that passes all the test cases.

5. Learning Data Structures and Algorithms

After starting your CP journey, it is recommended that you learn data structures and algorithms as most questions are based on these concepts. Being able to solve more problems will boost your confidence.

6. Upsolving

Platforms like Codechef, Codeforces host contests at least once every week. Generally, every contest contains 7-8 problems that go from beginner to advanced level. After the contest is over, the problems are always discussed in discussion forums and blogs on both websites. You can post your doubts there. Editorials are also posted on YouTube. Even if you are not able to solve all of them during the contest, you can read others' approaches to the code, watch the editorials and try to write the code on your own. This will greatly improve your performance in the next contest.

Conclusion

"You will never be ready. Just start."

Competitive coding is more about learning, practicing and dedication than perfection. You do not have to be able to solve all the problems on the first go. Consistency is the key. Keep practicing as much as you can and Voila! You are on the way to becoming a very good Competitive programmer.

So learn the basics and start your CP journey today! All the best!

S

Great write-up and a brief guide for beginners who want to get into CP. Thanks for sharing. Welcome to Hashnode!

2
M

Great advice Kusumita for those who would like to start in competitive programming. Personally, I do not really value competitive programming too much. Learning complex algorithms and the overoptimization of them has very little value in real life. Only a few percent of the jobs really need it. Of course, it can form your thinking but there are other ways for that too, like solving real-word problems, which won't get as repetitive as doing the 100th of HAckerRank challenge.

Also, programming at a very fast pace can do more harm than good. It is much better in case you take the time to think through and design your solution, which will be much more profitable in the long run.

Believe me, I had to solve many of those challenges at university, but haven't seen them in my 15 years of software development career. In my opinion, those challenges are only good for one thing, to get into companies who think that you can measure a developer by how much he/she practised the coding challenges for interviews, instead of checking whether he/she can solve a real-world problem.

Just my 2 cents. 😊

3
M

Would beg to differ, for some checking problem solving skills boils down to checking acumen of an individual. Having the right set of tools to solve an algorithm based problem arguably should be no different than finding solutions to so called real world problems. Although i dread algorithms too because of the initial complexity that i find to learn and apply, but that's the fun part if you're in your comfort zone always, you're not growing enough! Maybe this can be a little meta "talk", also highly subjective too.

But these were my two cents.

1
M

I do see a huge difference. Understanding, analyzing decomposing a real world problen, then designing and implementing a solution is not comparable to memorizing some well-known algorithms and data-strucrures Milind Mishra⚡️.

I was able to do the latter one during my grammar school years, but it took me many years to be able to do the first one.

Just my 2 cents of experience. 😊

2
M

Love the experience that reflects from your words! Miki Szeles

Also its not always memorising it but using up the algorithm to neatly apply in a problem just like we use libraries and frameworks to get our jobs done customised with our needs. But thats definitely a long topic of discussions.

10
M

Yeah. Knowing those algorithms are good of course, I am just trying to tell it is not enough. Despite this most interviewers test whether you practiced "enough" for the interview or not Milind Mishra⚡️

I would definitely sooner hire into my team someone who has no idea what are red-black trees, but who can analytically think and use google than someone who can implement red-black trees by heart.

Of course there is no problem with knowing what are red-black trees, but knowing it does not tell anything about whether you are a good developer or not.

I will be honest, I do not know what are red-black trees, but if I will ever need to know it, it won't take more than 20 minutes to google and understand it. 😊

M

Don't get me wrong, I am not proud of not knowing what are red-black trees, but according to my experience, 99% of developers will never face it during their career which is also true for everything we were taught at grammar school and university. Milind Mishra⚡️

M

Ofcourse, I understand that working on something like development technologies can make up the mindset like that, but let's not forget the roots and how the rigorous effort can make one better at solving problems, be it it any domain as fast as possible. It should be respected enough because it builds a culture in a software engineer to think computationally. Nothing less but respect to your advice. But equally important is to go through a journey. Irrespective of things having to come in way or not, which highly depends on needs of the industry, we should go through a set curriculum in order to let's say we need to study ahead, these strong programming and data structure fundamentals will help an individual shine! Miki Szeles

10
M

Still not convinced Milind Mishra⚡️.

The current education just su*s the approach how they are trying to teach is just outdated as it was outdated 20 years ago too (of course I can only tell about Hungary).

Just read a Head First book, and you will start to grasp the feeling what I am talking about.

Just look at the information density of such a book. Well it is medium, not tii light, not too heavy.

Instead of pushing as many programming paradigm or design patterns or algorithms into a book, we should favor quality over quantity. Provide as many additional highly or just lowely related material, play around with ine thing. Examine it from every perspective, come up with dozens of solutions from which of course one will be the most performant, but still the others are equally important.

I would much earlier leave my son in his room for a day with 1 toy, than giving him a dozen of toys and a coach with a stopwatch.

Just my 2 cents (by the way, I really enjoy this conversation. This is my longest Hashnode conversation up till now. Thanks man. 😊)

M

I just realized I just poked the bear as you are writing about inerviewing practice exercises. Milind Mishra⚡️. Sorry, do not take my rant personally. 😊