How to start with Competitive Programming ?

Competitive programming

only the word is enough to put a spark in every computer science student’s eyes. It is the latest fad among college students and a need of the hour for developers in every almost every domain. In my opinion, it’s a sport.

But, When, Where and How to start, What is an Online Judge ( is it an actual human ? ). These are the first thoughts that come into every beginner’s mind when for the first time he/she dives into this world of competitive programming ( or should I say Multiverse), I will be answering in this article:

Frankly speaking, in India, a person gets to know about competitive programming in the 1st/2nd year of college, and I feel that it’s quite late as compared to the world wherein Western and European countries it is a common subject from school levels.

When to start ?:

As soon as you got to know about it because everyone else you will compete with had already done it before. But till when?
There are two kinds of person out there

  • One who does this for getting a job by clearing the coding interviews
  • The other kind one who just love doing this as a hobby or as favorite time pass.

So decide yourself till when you want to do it but starting early has always ended up to be fruitful.

Where to start?

There are so many online resources for this and some great books too. Some of them are:

But, for a beginner, it is more important to know how to start on any one of these like, what is a problem, where to write a solution, and in which language? Almost each of these listed above support every popular programming language like C, C++, Java, Python, Javascript, etc.

| Also Read | Why Python Language

How to start?

There is a problem statement given which explains the input, output formats and what functionality needs to be satisfied by the program. You need to submit the program that accepts the input in the specified format, do something that outputs in a given format, only.

Now, coming to that “do something” part I mentioned in the above line.

One needs to think the algorithmic approach to reach the solution not for just one, but for all and universal inputs. By that I mean think about all possible input domains and then form a strategy common to all of them to reach the specified output. This needs both logical thinking and a lot of practice. Observe the problem statement and compare input and output for some easily thinkable cases. Then go for the corner cases that define the problem.

  • The basic rule to stay in the competition is, Practice and practice a lot.
  • Solve problems in linear order on any one of the mentioned websites.

Bonus (Solutions)

Here is a link to some beginner level solutions to Hackerearth problems that I wrote in the 2nd year of college, after getting a list of errors for straight 3-4 months. Most of them are in C as it was my first programming language and rest in Python3, my present language.

  • on the top, every solution has a link of the question statement on Hackerearth.
  • It is possible that there might be an efficient approach to the same question is possible but as I mentioned earlier these are the first thought solutions, which are then optimized by me to clear all test cases.

Now the good part of these solutions is that they use a naive and easier approach, not like the straightforward approach explained in an editorial solution of these. For example, the problem “PrimeStrings“, I had written a basic, first thought based solution to it, what a beginner could think of. Instead, when now I look back at it, I feel I could have optimized or shortened the code by using data structures like “set” and “dict“, but these things don’t strike in the first try.

Online Judge:

It is also a program that evaluates your code with respect to given problem and constraints. It already has both the input and output files that will be used for testing. Now when your program is made to run on those input files, it generates some output files w.r.t your code. Now, these are matched with the correct output files, present on the server. Based on this, you get a response that whether your solution was correct or not. Learn to make the online judge your friend and know the error it is throwing on you. It will help in debugging the program.

What to do if stuck?

Whenever stuck on a problem, just don’t give up and keep trying to approach it differently.

  • Only see the editorial solution after trying for at least 10-20 times.
  • Then learn from it, learn the way the solution has been thought of rather than the code.
  • Then start a newer, harder one.

Post any query/comments related to this post and we will be happy to solve it together.

Happy Coding!

Bhavesh Gupta

keeps it simple and automates the rest. gritty & lion-hearted when it comes to resolving bugs. Student | Problem-solver | Logical-thinker