Getting Started With Competitive Programming

This document is to guide those people who want to get started or have just started with competitive programming.

What is Competitive Programming?

Here is the definition of Competitive Programming from Wikipedia:

Competitive programming is a mind sport usually held over the Internet or a local network, involving participants trying to program according to provided specifications. Contestants are referred to as sport programmers.

In other words, it is a type of contest where a number of programmers solve some programming questions in a limited amount of time.

Benefits of Competitive Programming

So, we now know what competitive programming is. But before getting started we should know some of the benefits of Competitive Programming:  

  • Problem-solving: In competitive programming, you solve a variety of real-world problems in limited time and with high efficiency. This helps you to learn how to analytically think and solve a problem and analyze it’s space and time complexity.

  • Coding interviews: Every large MNC or Product-based company prefers to have initial filtering round which consists of Competitive Programming problems. Today, most interview questions of tech companies are level 2 or 3 problems that most Competitive Programmers anyway solve.
  • Get in your dream company: Various companies like Google, Facebook, Amazon, etc conduct online coding competitions like Google Kickstart, Google Hashcode, etc and they directly hire candidates based on their performance in these competitions.
  • Profile building: When you solve questions on a particular platform or in some competitions, then you are building your profile on that particular platform. Many companies tend to hire candidates, based on their profile on some online coding platform.

Key things required to be regular in Competitive programming

  1. Patience: The most important thing you need to learn is patience while doing the problems. Anyone who starts competitive programming as a beginner face impatience and the reason behind this is that he/she is able to solve the problem even after trying that problem for the last 2 or more days, and this leads into impatience.

     

    Every expert was once a beginner.

  2. Regular Practice: Participate regularly in as many as contests you can. Participating in the contests will help you in learning many new topics and you will get experienced how to compete with the programmers from across the globe.

How to get started with Competitive Programming?

  • Learn a programming language: Any programming language will do. But most problems are set with C/C++ and Java programmers in mind, so knowing any one of them will be really helpful. We will focus on C++, JAVA is slow (one big advantage of JAVA is Big Integers, we will see later). Sometimes knowledge of Python is helpful when you really need big integers.
  • PARTICIPATE PRACTICE PARTICIPATE: You will find many online judges on the internet. Here is a small list of the most popular ones:
    • SPOJ: Its a problem Archive (recommended for all beginners)
      Start with problems having maximum submissions. Solve the first few problems (maybe 20). Build some confidence. Then start solving problems topic wise. Never get stuck for too long in the initial period. Google out your doubts and try to sort them out or you can discuss with someone (ONLY IN THE BEGINNING). Before getting into live contests like Codeforces or Codechef, make sure that you have solved about 50-70 problems on SPOJ.
    • CodeChef: Do all the three contests every month.  Must participate in CodeChef LunchTime for sure. Even if you are unable to solve a problem do always look at the editorials and then code it and get it accepted (this is the way you will learn). And even if you are able to do it, do look at the codes of some good coders. See how they have implemented. Again you will learn.
    • Codeforces: 4 to 5 short contests of 2 hours in a month (Do them once you develop some confidence).
    • HackerRank: HackerRank has a good set of problems for beginners placed in a well-defined manner according to the tags and difficulty levels. The main thing that HackerRank provides to the users is that if you get stuck on some problem from very long time and only passing some of the test cases, then you can download the test cases and you can review your logic to do some modifications, it will help in thought process to be able to think about corner test cases. But seeing the test cases is not always good, after some duration(about 2 or 3 months) you yourself should be able to think that which test case might give WA(wrong answer).
    • TopCoder and HackerEarth: Both have a very good set of tutorials.
  • Learn about time and space complexity: In competitive coding, time and space complexity is the most important factor because for every question there is some time and space limit and within that limit, your code should run. In most of the cases, the time limit is 1 sec and the space limit is 256 MB.
    We all know the computation power of a processor is also limited. Assume 1 sec ~ 10^8 operations per second. You cannot allocate more than 4 MB space inside a function (it gives segmentation fault). Thus if you have to make an array of size >= 10^6, make it global or use dynamic memory allocation.
  • Learn Data Structures: Data Structures are something that helps you in making the program more efficient. Having a good amount of knowledge in Data Structures will help you in selecting the optimal Data Structure for any problem. 
    • Vectors
    • Stack
    • Queue / Priority_queue (heap)
    • Map
    • Set
    • Tree
    • Trie
    • Graph
  • Learn Standard Template Library (STL): In your code sometimes you need some data structures and some functions which are used quite frequently. They already have lots of standard functions and data structures implemented within itself which we can use directly.
  • Learn Algorithms: Algorithms are something that uses various data structures to implement the logic and then we get the result in the form of output produced by the algorithm. You need to be very good in Algorithms.
    Concepts that you need to know:
    • Time and Space Complexity
    • Recursion
    • Searching and sorting
    • Backtracking
    • Bit Manipulation
    • Greedy approach
    • Dynamic programming
    • Number theory
    • Game theory

Learn by doing

Solve as many problems as possible and try to solve different problems. If you are stuck in some problem, then try harder and if you are not able to find the solution then see the hint or the solution of other users and try to code once on your own. So to master Competitive Programming you need dedication, patience and continuous practice to solve the problems as many as you can.

Slow and steady wins the race

Happy Coding.

– Preethi Hena

Leave a comment