AfterAcademy Tech
•
22 Jan 2020

While going for an interview of your dream company, the biggest fear that most of the candidates have is the coding questions because every interview consists of some kind of coding rounds where you will be having one problem and you need to solve that problem in a limited amount of time. At that time, if you haven't done competitive programming before, then you will start regretting. So, don't worry, in this blog, we will see how to get started with Competitive Programming to crack the coding interviews. Below is the timeline of this blog:
So, let's get started.
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 simple words, it is a type of contest where a number of programmers take part to solve some programming questions in a limited amount of time. Either the contests can be online on various coding platforms or it can be held offline in some schools or colleges or organizations.
So, we have seen what is competitive programming and before starting it, we should know some of the benefits of Competitive Programming:
So, these are some of the benefits of Competitive Programming. Now, let's see how to get started with Competitive Programming.
Follow the below steps to get started with Competitive Programming:
Choose one language
Before starting, you should be familiar with at least one programming language like c++, java or python. If you know more than one language, then you should choose the one in which you are more comfortable. Also, try to choose some object-oriented language. Most of the people use C++ for Competitive Programming.
Choose an online platform
There are many online coding platforms where you can practice and take part in some online challenges. So, choose any one and start solving problems. Some of the online coding platforms are Hackerrank, CodeChef, HackerEarth, etc.
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. (Learn about Time and Space complexity from here)
Learn Data Structures and Desing & Analysis of Algorithms
Data Structures and Design & Analysis of Algorithms is very important for solving a question in the best possible way. Some of the Data Structures that you need during Competitive Programming are:
Concepts that you need to know:
Practice more and more
Start practising problems on online coding websites and also participate in coding contests. Also, try to solve questions of the past coding contests and other problems available on the website. You can also practice selected questions of every topic from here.
While attempting some question on any website, you will encounter some terms that will be present in almost every problem. Some of these terms are:
Problem Statement/Description
Every question will have one paragraph that will show the problem description. Here each and every detail of the problem will be given i.e. what to do? Read the problem statement carefully. Sometimes, to make the problem more realistic, the description may be large. So, read it carefully.
Following is an example of the Birthday Cake Candles problem from HackerRank:

Input/Output format
The input/output format of the questions in competitive programming is different from the normal input/output format that we use. For example, if we want to take input in an array, then normally we do the following:
Enter the size of an array: 5
Enter data: 1 2 3 4 5
But in competitive coding, the above will look like this:
5
1 2 3 4 5
So, have a close look at the input format of the questions in competitive coding and take inputs and give outputs accordingly.
Constraints
For some questions, you will be given the information about the input sizes i.e. the range in which the input data can vary. This will help you in deciding the time complexity of your code because the time complexity is proportional to the input size. So, always work according to the constraints given. Following is an example of constraints:
1 <= n <= 10^5
1 <= arr[i] <= 10^7
Sample input/output:
Each question will have some sample input/output that will show the explanation of the problem with the help of one input and the corresponding output. So, you can take help from that explanation and write your code accordingly. For example, if you are finding the sum of elements of an array, then the sample input/output can be:
Sample Input:
5
1 2 3 4 5
Sample output:
15
Explanation
In some questions, you will get the explanation of the sample input and sample output. This is just for understanding the purpose of the user.
Testcases
Testcases are the inputs and output files on which your code will be validated. When you write code, then the validation of the code is done with the help of some test cases and if your code passes all the test cases then your code is right otherwise, you need some improvement in your code. So, test cases are basically input files along with output files that verify your code.
Some test cases are public and you can see them and write your code accordingly if there is some error. But some test cases are private i.e. those test cases are not visible to users but they are used for code verification.
Time and space limit
In some cases, you will be given time and space limit of your code. Generally, 1 sec time and 256MB space are given to run a particular code. If your code is using more than the allowed time, then you will get the Time Limit Exceed error or simply TLE error and in that case, you need to reduce the complexity of your code.
There can be many ways of solving a problem in some competitive coding. You can follow the below steps to solve a problem:
Always participate in Online Coding Contests that happens regularly on various websites. If you are new, then you will learn a lot of things like how to approach a problem and find the best solution. These online challenges maybe some hiring challenge for the company or some reward will be given to the users. You will learn to solve problems in limited time and in an intense situation and you can apply this is your life also. Some of Online Coding Contests are:
Apart from these online contests, you can find many college and organisation contests on HackerEarth, HackerRank and CodeChef.
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.
Slow and steady wins the race
Instead of solving many questions in one day and then not solving any question in the next few days, you should make a target that you will solve the minimum "n" questions per day. You can increase this limit but never decrease the limit. For example, make a habit of solving 4 questions daily and by the end of the year, you will solve 365 * 4 = 1460 questions 🙂
Practice some selected interview questions.
So, start Competitive Coding and you will land yourself in your dream company. Also, let us know if you face some problem while starting Competitive Programming or solving some question.
Connect with us on Twitter and LinkedIn.
Happy Learning 🙂
Team AfterAcademy!
AfterAcademy Tech
In this blog, we will learn how to get started with Tensorflow 2.0. This blog is for both beginners as well as for advanced users who want to get started with Tensorflow 2.0 for Machine Learning.

AfterAcademy Tech
In this tutorial, we are going to learn about Express.js, why it is used, what all features it offers, and how it is used in the development environment. This tutorial will provide you with the most basic and important knowledge that is required in order to use Express in web application servers.

AfterAcademy Tech
In this blog, we will learn about the concept of hashing in programming. We will learn about Direct Address Table, Hash Table, Hash Function, a collision in Hash table. So, let's get started.

AfterAcademy Tech
Dynamic Programming is one of the most commonly used approach of problem-solving during coding interviews. We will discuss how can we approach to a problem using Dynamic Programming and also discuss the concept of Time-Memory Trade-Off.
