Exploring the Lesser-Known Benefits of Competitive Programming
A post about how doing Competitive Programming makes you a well rounded Software Engineer.
I work as a software engineer at CodeChef - one of the top Competitive programming sites.
I used to do a lot of Competitive programming in my college days, and then I moved on to doing development full-time. Now I usually give contests on CodeChef.
There are many misconceptions about starting CP (I will use CP as shorthand for competitive programming from now on). The prominent ones are
You have to be pretty smart to do it.
There is a lot of math involved.
It has no resemblance to real-world programming.
Let me tell you, all of them are very wrong assumptions. To get started with CP, you need basic knowledge of any one programming knowledge. Once you know that, you can quickly solve around 100 problems on CodeChef. Learning any programming language's basic syntax would take up to a week. How can something so easy to get started with be only for smart people?
Being better at math helps you solve CP problems, but you will need nothing more than your 10th-grade math to do good in CP.
The first two misconceptions are about limiting yourself by thinking that CP is not for you, but the third is very important as it is about rejecting CP altogether. I want to expand more on the third misconception today - about CP having no resemblance to real-world programming.
If we talk about the benefits of doing CP, you would know how people who do CP get referrals and interviews, clear them, and get jobs at good tech companies.
Today, I will focus on how doing CP helps you become a better software engineer.
List of all the benefits you get from CP:
A structured and easy way to start with programming
Improves your problem-solving skills
You learn to read other people's code
You learn to debug and test your code
You learn to learn
A structured and easy way to start with programming
At the start of our college lives, all the CS people know they should be learning programming to have better chances of getting a job out of college. But nobody knows where to start. I was in the same boat once. I wanted to do something in CS but did not know where to start. Thankfully I had a college senior who was good at CP and guided me on the path.
Let me tell you what I did. I started learning the basics of Python online. Python syntax is like English, so you can focus on writing programs instead of memorizing the syntax. After learning the basic syntax of Python, I started solving programming problems so that I could apply whatever I was learning. After solving around 100 problems, I began to get stuck on problems. I discussed this with my senior and got to know that there are so many Algorithms, Data structures, and techniques that you can learn and use to solve problems. And this world of problem-solving using DSA is what people call Competitive Programming. I started learning algorithms whenever I got stuck on a problem and then solved the problem using my newfound knowledge. I also started participating in contests, preparing for ICPC, etc.
This is as easy as it can get, only a week of learning syntax, and then you can write programs that solve real-world problems. There isn't an easier way to get started with computer science.
Improves your problem-solving skills
After solving a few CP problems, you will realize that it doesn't make sense to start writing code as soon as you read the problem. Your first approach will have gaps, leading to a wrong code. You first have to spend time trying to find a solution that works in all cases. You must break the problem into parts, look for edge cases, etc.
This process of structuring a problem, breaking it down into subproblems, and using the solution of those subproblems to stitch together a complete solution is called problem-solving. With this skill, you will be able to solve problems that previously seemed very unstructured or superficial. You will learn to give structure to your thoughts before even attempting to solve a problem. And when you solve it, you will solve it in a way that it is solved for all the cases, not just a few.
These skills are beneficial at my job as well. Most of the problems you encounter in your job are unstructured and not clearly defined. You have to provide a structure to them, look at edge cases and solve such that the complete problem at hand is solved.
You get used to reading other people's code
While solving CP problems, you will find yourself in situations where you know the solution but don't know how to implement it. At that point, it makes sense to look at other people's submissions and see how they have implemented the code. In doing so, you will find yourself learning newer techniques every day. Thousands of people solve every single problem on CodeChef. They all write very different codes. Some solve the same problem in 2 lines, while others would take 20 lines. Some would use standard libraries, and others would write their own functions. Even after you have solved the problems, it is very helpful to look at how others have solved the same problem. You will learn a lot. Also, while reading other people's code, you will learn to differentiate between good and bad code and try to write good, readable code.
Again, this skill is essential in your job. You will be reading code written by others all the time. Whether fixing a bug or writing an altogether new feature, you will have to read the code to understand its structure, best practices, etc., and then modify that code. Your efficiency as a software engineer will depend a lot on how fast you can get into unknown codes, understand them and extend them.
That brings me to another one of the important benefits of doing CP - learning to debug code.
You learn to debug code
As you move on to solving complex problems, you will make more and more mistakes. With the increase in the number of lines of your code, your mistakes will also increase. At that point, knowing to debug your code will make the difference between actually solving the problem and quitting. I have seen many juniors send me code that doesn't work and ask me to debug that for them, saying they have been looking for hours when they are making small silly mistakes.
With time you will understand how techniques like print debugging, dry running, or reading each line of your code aloud make you 10x more efficient in debugging your code and getting unstuck fast. As you get better at debugging your code, you also start writing better code. After seeing so many different types of mistakes, you will, by default, write code that avoids those mistakes. You will also learn to test your logic and code before submitting so you don't have to spend hours debugging.
As you will be dealing with code all the time on your job, these skills of debugging, testing, and writing good code will make your team's and customer's life easier.
Final benefit: You learn to learn
In CP, you will learn new algorithms, techniques, or data structures every day. Initially, you will struggle a lot, but with time you will get better at learning these new algorithms and techniques. This my friend, will be the best benefit you can get from doing CP.
After doing CP for a year or two, you will be surprised by how easily you can pick up any tech stack and get up to speed. As you have honed your skill of learning new things in CP over the years, you will be able to pick any tech stack.
You have to apply the same handbook, learn concepts of the technology within a week or so and then start writing code. Learn more concepts as and when you get stuck. And when you get really stuck, read that technology's documentation or code on Github. You already know how to read other people's code. Nothing will remain magic for you. As you know, it is all concepts and code. And you already know how to read code and learn new concepts fast.
--
One final note I want to add is that CP is not just for CS folks. It is for everybody. Once you have learned the basic syntax of any programming language, you are good to start. You can learn everything along the way. In that sense, it is more like chess, you have to know basic rules to start, but you can get better at it throughout your life.
So, anybody who feels like they should start with CP today can start by learning the basics of Python or C++ from https://www.codechef.com/learn and start solving problems and participating in weekly contests that start every Wednesday at 8 PM.
You can find me on CodeChef at - https://www.codechef.com/users/justani. On Codeforces at - https://www.codeforces.com/profile/justani. And on linkedIn at - https://www.linkedin.com/in/justani.
