The Ultimate Guide to Competitive Programming

Chitra Singla
Codess.Cafe
Published in
9 min readMar 21, 2022

--

Hola readers! I am Chitra Singla, a final year Software Engineering student at Delhi Technological University. Recently, I have received full-time offers from Google and Amazon. Previously, I had done a 2-month summer internship at Amazon and am currently doing a 6-month Winter internship at Walmart.

Competitive coding holds a special place in my heart. I am currently rated as an expert on Codeforces and a 4-star coder on Codechef. With constant practice and being consistent, I was able to secure a rank of Global Rank 369 in Google Code Jam I/O Women 2020 and a rank of Global Rank 1114 in Google Kickstart Round C 2020. Apart from this, I have secured Global Ranks of 97, 462 in CodeForces round 713 and 642 (Div 3) and 140, 220 in CodeChef July and Feb cook-off rounds 2020(Div 2) respectively.

Disclaimer: It is to be noted that everything mentioned here is my personal view, hence there are high chances of difference of opinion at some places.

Through this blog, I will be addressing some queries related to CP regarding which people are often in dilemma. To make it fun, it is in a questionnaire format. Happy reading!

Table of contents:

[1] What is CP?

[2] Who should do CP?

[3] Is CP necessary for cracking placements?

[4] Which platform should one start from?

[5] When is the ideal time to get your hands into CP?

[6] What are the prerequisites?

[7] What is the ideal approach to solving questions?

[8] Importance of contests.

[9] How to deal with the situation when you are not able to solve questions?

[10] Final piece of advice for budding programmers

[1] What is CP?

Competitive programming is like a programming sport involving many participants competing with each other to achieve better results. A competitive programmer implements their algorithm and submits it to a contest system. Then, the algorithm is tested using a set of test cases, and if it passes all of them, it is accepted.

Image credits: beinghuman.ai

Competitive programming has proved to be an excellent way to learn algorithms, because it encourages to design algorithms that really work, instead of sketching ideas that may work or not. It involves the design and implementation of algorithms in an efficient way.

Many online platforms and companies host programming contests. eg: Hashcode, Kickstart, CodeJam by Google, and HackerCup by Facebook. One of the most famous competitive programming contests is ICPC (International Collegiate Programming Contest). Programmers can participate in these contests, check their understanding, showcase their skills, and can get a chance to win exciting goodies and prizes through these contests.

[2] Who should do CP?

Everyone should at least try to do CP once. It helps enhance one’s mind and develop analytical and thinking skills. It improves problem-solving and programming skills and helps in preparing for technical interviews. Solving competitive programming problems also improves one’s programming and debugging skills.

When you train yourself and participate in programming competitions, you become more disciplined, faster, and more efficient. In this environment, you solve problems and code with a tight deadline. This teaches you how to focus on a task and efficiently execute it.

[3] Is CP necessary for cracking placements?

No, competitive programming is not at all necessary for cracking placements but yes, it is highly recommended as it improves problem-solving skills. It helps in improving mental and logical ability as contest problems require thinking which in turn helps in solving complicated questions easily. It also makes the person faster and more focused.

On the other hand; in Web Development we learn tech stacks that change very frequently, so I prefer spending more time improving problem-solving skills than doing web development. Problem-solving skills are the core of every tech domain.

Image credits: geeksforgeeks.org

-> How to start CP?

Now the question arises, how to get started with competitive programming. Start with learning the basics of a programming language (it can be any one of C++ or Java, these 2 are the recommended ones). After learning the basics, start practicing problems. For this, you can start with HackerRank as it is the most beginner-friendly platform and helps to develop fundamental problem-solving skills easily.

After getting familiar with the basic problems, you can start practicing questions on Codeforces. It is one of the best platforms for competitive programming. Gradually start participating in contests and for every 3/4 hours of problem-solving, allocate at least 1 hour to learn and revise the concepts.

Learn Data Structures and Algorithms, start with time and space complexity analysis, followed by learning the data structures such as Arrays, Linked lists, Stacks, Queues, Trees, Heaps, Graphs, Tries along with the algorithms such as Searching, Sorting, Greedy, Divide and Conquer and Dynamic Programming.

Practice, practice, and practice as practice is the only way to improve in competitive programming.

[4] Which platform should one start from?

Codeforces is the best platform for competitive programming according to me. It organizes short contests very frequently, and the level and quality of questions are also very good.

They also have a feature of participating in a contest virtually which means that if you miss the live contest you can still give the contest virtually, the only difference is that in the case of virtual participation there will be no change in the rating.

Codeforces has recently introduced 2 new sections, Catalog and EDU. In the catalog section, topic-wise blogs related to CP are present which are written by the top coders. And in the EDU section, a course is present which contains theory and practice problems related to some important topics for competitive programming.

Other than Codeforces, there are many other platforms such as CodeChef, Topcoder, AtCoder, and many more.

[5] When is the ideal time to get your hands into CP?

Anyone can start at any time, there is no such thing as an ideal time because it depends on the motivation to do it. Some people spend 3–4 yrs and are still not able to improve whereas some people reach great levels in just 3–4 months so it all varies from person to person. My recommendation would be to start as early as possible.

[6] What are the prerequisites?

There are no prerequisites as such. You can learn the basics of any programming language like syntax, some basic DSA like Arrays, Strings, and algorithms like Sorting and Math. After that, you can start solving the questions and learn new concepts while solving the questions.

[7] What is the ideal approach to solving questions?

Read the question carefully, try to jot down all the points given in the question, no information is unnecessarily present there. After that try to identify the expected time complexity of the algorithm by analyzing the constraints given on the input. Then try to form the approach and optimize it as much as you can by using suitable data structures and algorithms.

If you are not able to figure out the algorithm, try to take hints either from friends or read the starting 1–2 lines of the editorial, and think of the whole approach yourself. If you are still not able to form the approach then read the editorial and implement it yourself. Again if you face any issue, then see the solution and analyze why you were not able to solve it, and make notes of the new things learned.

If you encounter a new method of solving the question or find something new like a trick note that down. Some examples of the tricks which might be helpful at times:

  • Using call by reference in case of vectors and strings instead of call by value
  • Using map instead of unordered_map as the worst-case time complexity of unordered_map is linear

Make short notes wherein you explain the que in 1–2 lines and its approach in 2–3 lines so that it doesn’t take much time to revise.

[8] Importance of contests.

Contests play a crucial role in improving problem-solving skills. Contest prepares you to solve questions in a timed environment, they help to feel the pressure of solving new questions in a given time limit. Many companies have their online coding test rounds so participating in contests will help you to perform better there.

Try to give each and every live contest and if due to some reason you are not able to give a live contest, participate in a virtual contest. Many online platforms allow you to participate in a contest virtually. Don’t feel demotivated if your ratings drop after the contest. Upsolving after the contest is very important. Try to solve at least one more question.

Let us suppose you were able to solve 2 questions during the contest then try to solve the 3rd one also after the contest and analyze the reason why you were not able to solve the question during the contest.

[9] How to deal with the situation when you are not able to solve questions?

There will be many times when you are not able to solve the question. There can be 2 reasons for this: One might be that the question will be solved by an algorithm or data structure that you are not aware of or it is a completely new type of question. So in this case, identify that and learn it and after that try to solve the question. The second case may be that you are familiar with the topic of the question but still, you are not able to think of the approach. In this case, try to divide the question into smaller tasks if possible and then try to solve, take hints and discuss it with peers. If none of this works, then see the editorial and try to analyze why you were not able to think of it.

[10] Final piece of advice for budding programmers

Participate in as many contests as you can. I often see students spending months on CP theory and never participating in a competition (online or onsite) fearing that they don’t know enough to start competing or fearing the pressure of a timed contest. Writing accurate and fast code is a huge part of CP and this can only be improved by getting into a live contest. Also, get yourself around people who enjoy CP. Being surrounded by such people will keep you motivated.

Since you made it to the end 🤗, here is a list of resources that I used in my CP journey

-> Websites for practicing

-> Books I used (Click on the links to access the free PDF)

-> Other resources

That’s all from my side! If you want to discuss any particular point or have any queries, feel free to reach out to me on my LinkedIn :) If this was helpful to you, do hit the clap button and follow Codess.Cafe for more such articles

Codess.Cafe: LinkedIn | YouTube | Website | Medium | Twitter

--

--