Competitive Programming Part-1

Hello friends, I am Shubham Agrawal, and today I have come up with a very crucial and most important trending topic: Competitive Programming, also known as "CP". Definitely, you must have heard this word in your life. But if you are a beginner and didn't hear this word, don't worry about that. I assure you that after reading this blog until the end, you will definitely be familiar with it. So without wasting our time, let's start with the question I know will arise in your mind.

 

Q.1) What will be the right time to start competitive programming?

 

Answer:- There is no age recommendation to start competitive programming. But if you want a better job package in the IT field, you should begin competitive programming now. If you're going to do engineering from any branch, especially computer science and information technology, then competitive programming is a must. And you have to start making code from the 9th standard because there are many things you have to study, like data structures and algorithms, etc., earlier. According to the new education policy, the competitive programming courses would also have operated from the 6th standard. So, pull your socks up and do competitive programming from now.





 

Q.2) What is competitive programming?

 

According to Wikipedia:-

 

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

 

In short, you can say, "It is a kind of sport of mathematics where you have a problem statement based on your thinking, and you have to read it carefully and try to implement it in any programming language you like."

 

After reading it, you may doubt, "what kind of questions are you talking about?" 

 

If you are a beginner who hasn't put their leg in competitive programming, then I try to understand you by a basic example:-

================================

 

Problem Statement:-

 

Rohit and Jaadu are very close friends and only trust each other. But Jaadu is very weak in mathematics even though he didn't calculate the sum of two numbers. But he is solid in magic. You can say he is a magician. So whenever Jaadu has a problem, he calls Rohit; whenever Rohit has a problem, he calls Jaadu. Once upon a time, Jaadu went to market alone and purchased two medicines, but when he was paying the shopkeeper, he got stuck in the calculation, and he called Rohit and gave two numbers to the Rohit. As Rohit is brilliant in maths. He calculates and finds the total amount to pay. 

 

               Suppose you are Rohit and Jaadu again got stuck in the problem. Jaadu gives you two numbers, and you must find the total amount Jaadu has to pay.

 

Input:-

 

 The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.

 

The first line of each test case contains two space-separated integers, A and B.

 

Output:-

 

For each test case, print the single line containing one integer – The total amount has to be paid to the shopkeeper by Jaadu.

 

Constraints:-

 

1<=T<=100

 

1<=A,B<=100000

 

Example Input:-

 

2

 

10 15

 

40 23

 

Example Output:-

 

25

 

63

 

Explanation:-

 

In test case 1, The sum of 10 and 15 is 25, and In test case 2, The sum of 40 and 23 is 63.

======================

 

If you closely observed the above problem statement, then all you need to do is, you have to find the sum of two digits. But competitive programming is more complex than I mentioned above. But yeah! The problem statement may vary from question to question, but the format remains the same. 

 


 

Don't panic if you have doubts about constraints, test cases, Input/ Output, and space-separated integers like that, don't panic. I will explain all of that one by one in this article. But before, I would like to clarify your doubts and queries so that you make it your area of interest.

 


 

Q.3) Why do we need to do competitive programming?

 

Answer:- As I previously mentioned, Competitive programming is a crucial and trending topic if you are in the IT field. Due to all this, it has become the most potent tool for top MNCs (Multinational companies). Even most companies hire their employees from top-rated competitive programming platforms. And rest of the companies conduct their own online contest. If you are strong in CP, you can qualify for any exam in an online game or TR interviews. 

 

I think now it's more than enough for you. And I hope you understand what CP is and its importance. Now, I move on to the following questions, where we will discuss "what are the prerequisites and tips and tricks to do competitive programming inefficiently." 

 

Q.4) What are the prerequisites, and which language is best for it?

 

Answer:- There are a few topics of which you must have knowledge about all that, and those are as follows:-

 

  1. Basic Mathematics and reading ability.

 

  1. At least one programming language, whichever you like( for example- C, C++, Java, Python, JavaScript, Ruby etc.).

 

  1. Data structures and algorithms.

 

  1. Ability to trace the code or the ability to dry run any code.

 

First, you need a programming language (C, CPP, Java, Python etc.). If you don't know any programming language, then sorry to say, but you can't able to do competitive programming. Please learn any programming language first. Here I recommend learning C language first, then moving on to the following programming language, whichever you like.

 


 

Preferred language:- If we discuss which language is suitable for CP, I recommend Python. The reason why I chose Python is that it is straightforward to use. After making the code dry run, the code is pretty simple. The readability of the code is best. Apart from it, Python has a lot of methods and functions. Due to this, we don't have to define the process explicitly.

 

Q.5)What are the "Test cases" and "Constraints"?

 

The concept of test cases can be better understood by the below diagram:-

 






 

And Constraints are nothing but the input range, or you can say it is the lower and upper range of the information, which means that the input size will not cross the lower and upper limit. It lies between the given field. The significant advantage of the constraints is that we can decide to make a variable accordingly. If the input size is not more than 2147483648(int range in c language), then the variable of int is suitable for that. We must make the variable length and, accordingly, if it crosses the int range. 

 

If you are a beginner, you may need help understanding my words, but you can cooperate with me when you learn any language.

 

Q.6) What are the best platforms for doing competitive programming?

 

Answer:- There are many programming practice platforms like Hackerrank, HackerEarth, Codechef, Codeforces, Leetcode and many more. But here I would like to share my own experience. When I learnt my first programming language, C language, I went to Hackerrank. It is the best platform for the beginner. After I was satisfied with Hackerrank, then, I went to HackerEarth. If you have already made code in those platforms, I recommend practising in Codechef or Codeforces. You can choose any platform first. It didn't matter. Do practice, guys. You do not have enough time. There is too much to learn. Happy coding!!

 


 

This is the first article on Competitive programming. In the following article, I will share some tips and tricks to do better in competitive programming. Sometimes it's happened that we create the whole program on our own, but at last, we get an error like TLE, NZEC, WA etc. And sometimes, we are not able to understand the problem statement. In the following article, I will share my personal experiences and how you can eliminate these errors. Thanks for reading this article. Please share it with your friends and colleagues. If you have queries and doubts, then it is always welcome. Leave your comment if you find something new in this article. 

 


 

**THANK YOU**

 


 

Comments

Post a Comment