Complete guide to kick-off Competitive Programming!
Where to start, which platforms to practise on, and the five things a beginner should keep in mind.
First published on Medium
Note from Author (Dhruv Kothari): Hello readers! This article is based on the beginner-friendly approach to competitive programming. All the opinions expressed in this article represent my own views, which I think are appropriate for a newbie in the world of competitive programming.
A competitive person is always a winner. An uncompetitive person is always a loser.
~ Dr. T. P. Chia
What is Competitive Programming?
According to me, competitive programming is a sport. A sport based on problem-solving skills, thinking ability, speed testing, regularity and precision. Competitive Programming will help you build logic and implement that logic to find solutions to a real-world problem. Brainstorming upon your code will definitely increase your coding skills, as well as it will help to expand your thinking capacity. Thus practising Competitive Programming on a day-to-day basis helps you in mastering that particular language. And believe me, if you are playing this sport regularly, you are already prepared for the technical rounds of the interviews. So now let’s dive into the ocean of Competitive Programming.
How to start competitive programming?
Frankly, there is no particular right time to start doing this, but it is advised to start as early as possible. We all have heard a great saying that — Early bird catches the worm. Right? Therefore it’s never too late to do this, but you should start the moment you get to know about it.
Just Begin. Take your laptop, a pen, and a book. Get a problem statement, start thinking about the logic, build the algorithm and then finally implement it.
Now, we all know that we live in the era of the internet, which brings us a lot of learning opportunities free of cost. So what are we waiting for — let’s utilize these opportunities. There are some amazing platforms for competitive programming through which a beginner can kick-off his/her journey.
HackerRank
According to me, this is one of the best platforms for a beginner to kick-off. Its UI is simple and user-friendly. There are different categories like problem-solving and algorithms, mathematics, statistics, language proficiency (C, C++, Java, Python), SQL and many more. The questions range from EASY to HARD to ADVANCED. Lastly, you are gifted with star badges which really motivates you to do more.
CodeChef
After spending a few days on HackerRank and achieving a few golden badges, you can start with CodeChef. Problem statements are of higher-order thinking than HackerRank, but if you are aiming to ace competitions like ACM-ICPC then this is one of the best platforms for practising. CodeChef organizes contests like Monthly Long Challenges, Cook-off, and Lunch-time, which show you your ranking/position nationally as well as globally so that you get to know where you currently stand globally.
A few more platforms for practising (intermediate level and above)
- SPOJ — Sphere Online Judge, spoj.com
- Codeforces — codeforces.com
- TopCoder — topcoder.com
- LeetCode — leetcode.com
- Project Euler — projecteuler.net
- GeeksforGeeks — practice.geeksforgeeks.org
- HackerEarth — hackerearth.com
Knowledge is of no value unless you put it into practice.
Most important things a beginner should keep in mind!
1. Always read constraints. Every problem statement consists of a question statement, function description, input-output formats, and most important constraints. They play a vital role in your code. Data types are chosen on the basis of constraints provided.
For e.g. talking about C++,
if constraints are like (0 ≤ arr[i] ≤ 10¹⁰), for this you can’t use the normal
intdata type. Here you have to go for thelong long intdata type.
2. Don’t write any additional code. Stick to the input format and don’t write any additional line in the code. For e.g. avoid writing in the traditional/inappropriate format like “Enter the number of elements in the array” and “The Output of the code is.”
3. Persistence is always greater than performance. Focus more on practice instead of expecting results on the very first day. “Wait! Even miracles take a little time.” So just be consistent, try to do at least 5 questions every day and spend a good amount of time on each question. Don’t give up easily. PUSH YOUR LIMITS and KEEP PATIENCE.
4. Analyze your code on the basis of time and space complexities. As a competitive coder it’s very important to know the time and space complexity of your code, because your code is judged on these parameters and hence you can improve your code by reducing these complexities.
5. Data structures and algorithms: stalwarts of coding. Without having proper knowledge of DSA one can’t go far in this journey. Keep a habit of learning new algorithms and techniques regularly and try to implement these algorithms while solving the problem statements. It will help you create code with reduced complexity with respect to time and space.
Tips and suggestions
- Don’t revolve around multiple languages. Stick to one language like C++ or Java or Python etc. In my opinion, I would recommend C++ over any other language because of its simple syntax and faster speed.
- Debug your code. It is very important to find mistakes in your own code so that mistakes can be avoided next time.
- Analyze others’ code. Generally, it’s a good practice to analyze other people’s code. For e.g. while doing problems on HackerRank, after completing a problem just go to Discussions and read other people’s solutions, which will give you better and unique ideas of doing the same question.
- Learn new things. Read about different coding styles and techniques like recursion, backtracking, dynamic programming and many more.
- And finally, LOVE YOUR CODE. I don’t think there is any need to explain it further xD. Right!
So what are you waiting for… just go and code!!!
Thanks for being with me until here. Here is a bonus point for you!
To visualize and debug there is a terrific website that provides live visualization so that you can track and visualize each and every line of your code. This is really a very handy tool for a beginner, as they can know the working of their code.
- C++ — click here for code visualization
- Java — click here for code visualization
- Python — click here for code visualization
A few must-read articles
- Getting started — CodeChef
- How to prepare for competitive programming — GeeksforGeeks
- Getting started with the sport of programming — HackerEarth
- The 10 most popular coding challenge websites — freeCodeCamp
- Data structures and algorithms certification — CodeChef
So, at last, I would like to conclude by saying that persistence leads to miracles. Hence practice, practice, and practice — and last but not the least, guide and motivate others to dive into the deep ocean of COMPETITIVE PROGRAMMING!
THANKS!