What is Competitive Programming?
Before I tell you how to start CP (Competitive Coding), let me tell you what it is all about. In CP, programmers compete with others to solve coding problems within a limited time taking all the time and space constraints into account and passing all the given test cases.
Why practice Competitive Programming?
As you rack your brains to find the best optimal solution that satisfies all the test cases, you sharpen your logical and analytical skills. With every code you write, your optimization game keeps getting better. This will give you an edge over the other applicants in any coding interview as you are accustomed to finding the best solution for any problem under time pressure.
How to get started?
1. Learn any Object-Oriented Programming Language
To start with CP, pick any object-oriented programming language (preferably C++, Java or Python) and get thorough with its basics - the syntax, loops, conditional statements, operators, arrays and some necessary built-in functions. Once you have familiarised yourself with all of these, you're good to go.
2. Choose any online platform
Now, it is necessary to practice problems and participate in online contests to keep a constant check on your progress. Codechef, Codeforces and HackerRank are some coding platforms you can begin your CP journey with.
You can start by solving easy questions by searching practice problems by their difficulty rating.
3. Learn about Time Complexity and Space Complexity
In CP, knowing about time and space complexity is important as almost in every question, the time limit to run on all test cases is 1-2 seconds and the space limit is 50000 bytes (approx .05 MB) on Codechef and 64-256 MB on Codeforces. Hence, your code has to perform the necessary operations in the least number of lines of code possible.
4. Understanding the Problem Statement and the Input/Output format
Look at this Codechef problem carefully. It has 4 important sections:
i. Problem Statement:
Make sure you take some time and read the problem statement carefully. Sometimes the problem statement can be lengthy, so you may want to note down the necessary points.
ii. Input/Output format:
Unlike the normal input method, where we generally provide inputs one at a time, in CP problems, the entire test case is provided as the input at one go. So, keep the input and output format in mind and write the code accordingly.
iii. Constraints:
In a problem, there will always be a few variables mentioned. Under the constraints section, the range of the values across all the test cases (both public and private) for each variable is mentioned.
Here, the value of N ranges from 2 to 50, so we assign the Integer data type.
However, if N would have ranged from 2 to 1010, we would have to assign the Long integer data type.
iv. Sample Cases:
The sample cases tell you what the input and output of the program will look like if it is unclear from the problem statement. Sometimes, it also gives away any loophole in the problem statement which you can make use of to write a simple solution that passes all the test cases.
5. Learning Data Structures and Algorithms
After starting your CP journey, it is recommended that you learn data structures and algorithms as most questions are based on these concepts. Being able to solve more problems will boost your confidence.
6. Upsolving
Platforms like Codechef, Codeforces host contests at least once every week. Generally, every contest contains 7-8 problems that go from beginner to advanced level. After the contest is over, the problems are always discussed in discussion forums and blogs on both websites. You can post your doubts there. Editorials are also posted on YouTube. Even if you are not able to solve all of them during the contest, you can read others' approaches to the code, watch the editorials and try to write the code on your own. This will greatly improve your performance in the next contest.
Conclusion
"You will never be ready. Just start."
Competitive coding is more about learning, practicing and dedication than perfection. You do not have to be able to solve all the problems on the first go. Consistency is the key. Keep practicing as much as you can and Voila! You are on the way to becoming a very good Competitive programmer.
So learn the basics and start your CP journey today! All the best!