Competitive Programming — A Beginner’s Guide.

Pranat Sharma
Software Incubator
Published in
5 min readNov 30, 2019

What is Competitive Programming (CP)?

It is basically a mind Sport where you are given some problem and you are required to give an optimized solution under various constraints by using your programming skills. This sport basically tests your Logical thinking, Analytical Thinking, Pattern Recognition, Pressure Handling, and most importantly your knowledge of Data Structures and Algorithms.

Why CP?

There are many reasons for doing CP:-

  1. It’s an awesome brain exercise.
  2. Helps to build your Problem Solving Skills.
  3. You will get used to working on challenging problems.
  4. The adrenaline rush you experience when your code gets accepted is just amazing.
  5. Being good in CP increases your chances to land in good Product Based Companies like Amazon, Microsoft, Google, etc. which look for people who are strong at Data Structures and Algorithms. And getting good at CP requires being good at Data Structures and Algorithms.

Where to Start from?

These are some steps to start your competitive Programming Journey:

1 Learn a Programming Language :

Some most used languages for Competitive Programming are C++, Java, Python. Although Python is simple and easy to learn, it is a relatively slow language. Even python is not allowed in some contests.

Java is also preferred by some people but the Java Codes are longer to write. Also, you may get TLE(Time Limit Exceeded) in some cases due to being slow on the time limit side.

C++ is the fastest among Python and Java and is comparable to C. C++ offers you a very powerful Library STL(Standard Template Library) which makes many things easy for Competitive Programmers. (Ex. Predefined Functions for sorting, searching; Vectors, Sets, Maps, Pairs, etc.)

I personally prefer C++ for Competitive Programming.

Resources for learning C++:

2 Start practicing and take part in Contests:

As a beginner, start with the Problem Solving Section on Hackerrank. Cover Topics like Implementation, Strings, Sorting, Searching, Greedy, Bit Manipulation in order of Easy-Medium-Hard. Try to get 6 stars in it and you will begin to feel that you have learned a lot of new things. Your code length will decrease and you will begin to write more efficient code.

Meanwhile, take part in contests on sites like Codechef and Codeforces as they are a great way to learn some new concepts. In the beginning, you may find the language of problems a bit hard to understand but after some contests, you will get used to it.

Also, don’t forget to up-solve the problems which you were unable to solve in the contest.

Resources:

Youtube Channels to follow :

3 Learn Data Structures and Algorithms :

While practicing and taking part in contests, get your hands dirty on Data Structures and Algorithms.

This is the most important part where you learn how to make your program more efficient. Having good knowledge of Data Structures will help you in selecting the optimal Data Structure for a problem.

Important Data Structures for Competitive Programming:

  • Arrays
  • Strings
  • Stacks
  • Queues
  • Linked Lists
  • Heaps (priority queue)
  • Disjoint Set Union
  • Graphs
  • Trees
  • Segment Trees
  • Binary Index Tree (Fen-wick tree)

Important Algorithms for Competitive Programming:

Algorithms required to solve problems in a Coding Contest

4 Practice, Practice, and Practice:

Practice is the key to success in Competitive Programming.

There are many platforms out there where you can get to practice numerous problems. Now after getting some good knowledge of DSA, start participating in Short Contests.

Some of the most popular platforms are:

Contests to watch out for:

  • CodeChef Starters(for beginners)
  • CodeChef Long Challenge
  • CodeChef CookOff
  • CodeChef Lunchtime
  • Codeforces Div 3 (for beginners)
  • Codeforces Contests (Div 2, Educational Rounds and Global Rounds)
  • AtCoder Beginners Contest
  • AtCoder Regular Contest

Do’s & Don’ts in Competitive Programming

  1. While practicing on any platform, do not look into the solution/editorial without giving your best. Peeking into the solution will not do any good for you. Always give your best to find a solution to a problem. Even after an hour or two, if you are unable to get any approach to the solution then look at the editorial/discussions and try to thoroughly understand the Code and then implement it by yourself.
  2. After the contest gets over, always try to up-solve the problems which you were unable to solve in the contest. This is where real learning starts. Look at Editorials and discussions.
  3. Do not hesitate to look at the solution of other people/friends after the contest. Maybe your friend’s approach could be better than yours.
  4. Do read Blogs on Codeforces written by High Rated Coders. You will get to learn a lot from them for sure.
  5. Do not stick with just easy problems. Get out of your comfort zone and challenge yourself. Start solving problems that really push you.
  6. Make a company of friends who also enjoy CP and have healthy competition with them. Discuss your doubts with them(Obviously not during a contest ).
  7. Do not really worry about ratings on various Coding Platforms. Rather focus on your growth. Your rating will automatically increase if you focus on learning.
  8. Do not get demotivated or disheartened if you cannot perform well in a contest or cannot solve a problem. It happens. Just learn from your mistakes and try not to repeat them again.
  9. Competitive Coding is much more about practice. It takes time to become a master in it. So never give up(unless you don’t really enjoy doing it) and never have self-doubt upon yourself.

You can analyze your performance using this awesome website: StopStalk

--

--

Pranat Sharma
Software Incubator

Python Developer at Software Incubator | Div-1 at Codechef