Competitive programming is essentially about writing code to solve a well-defined problem. Willam Lin summarises what is competitive programming in a video.

In this post, I elaborate on my experience in competitive programming, and some of my advice for people starting out.

My Competitive Programming Journey

I liked competitive programming before knowing what it was. My first competitive programming experience was the coding midterms in Spring 2018. I find solving coding problems in a time constraint fun, and I did pretty well in the midterms relative to the rest.

In 2018 September I got two of my friends to do a 36-hour long onsite challenge at Credit Suisse. We did well as beginners, ranking at 13th place among around the 20 teams who persisted to the end. We were tasks to deploy an API, and the test cases are sent as HTTP POST requests. One of my groupmates who had real software engineering experience helped to set up the workflow.

Then the earliest contests that I participated in was Leetcode, in December 2018. There was this interesting weekly contest, which felt like my midterms. In the first few contests, I could solve the first two questions, and after a few practices, I could consistently solve three out of the four questions. The contest happened regularly on Sunday at 10:30 am Singapore time, and it has soon been my routine since.

In 2019, I participated in a few more onsite contests, at Facebook, Credit Suisse (again) and Bank of Singapore. I got the top three for each of the contests.

fb-hack-2019

In the summer of 2020 during my remote internship, I started serious competitive programming practice on Codeforces and AtCoder. As of summer 2021, I have done a combined total of more than 100 contests.

I also participate in programming challenges held by companies. I won a T-shirt from Facebook HackerCup 2020 (which is currently my favourite T-shirt). I got into Round 2 of Google Code Jam 2020 (but I need to get into Round 3 for the shirt). I also participate in the qualifiers of Google Hash Code 2020 and 2021, a team challenge where you produce a submission that maximises a certain score subject to constraints.

However, I had never represented my school in competitive programming (in competitions such as IOI or ICPC). I only started learning to code in university, and by the time I was pretty good at contests, my graduation was near.

In early 2021, I participated in two hiring challenges. I got nice placings in Indeed programming challenge and Quora programming challenge. I was invited to apply and managed to advance to the final interview stages.

Goals and Reflections

I hope to attain the rank of Master on Codeforces, which has a nice yellow color for the title (which I did).

I have met quite several people from competitive programming. I am still in contact with two of the people I participate FBHack with. There are a few people who reached out to me through my Leetcode and Codeforces profile, and I had some meaningful conversations with them.

I am proud to call competitive programming my hobby. Even after I start my first role, I will continue probably with at least the weekly Leetcode contests.

Appeal of Competitive Programming

Competitive programming is like solving puzzles, but with code.

Any method or theorem I have learnt in the past may be applied. While most of the questions are centred on data structures and algorithms, some questions require the application of number theory, geometry, statistics and game theory. At times, the challenge is see the applicable concept which may not be immediately obvious.

It helps me to code rigorously. Competitive programming scores are usually all or nothing, and I need to take care of all of the corner cases. I also need to be careful with implementation especially when my approach gets more complex. Wrong submissions almost always result in a small penalty.

It helps me to practice researching efficiently. Online contests, unless specified otherwise, allow you to access any pre-existing resources. The only restriction is that you are not allowed to communicate with anyone. Sometimes I need to implement algorithms that I have never heard of before. I need to efficiently and accurately estimate the usefulness of the resource and apply it to the problem.

It has also help me develop a structured workflow. I wrote simple macros to make running test cases more efficient. I have also compiled code snippets that might be relevant across competitions. I am also more comfortable with the basic git commands as I create a branch for every contest I participate in and commit my code at some of the checkpoints.

Advice for beginners

Tech interviews usually have online assessments, which is very similar to a Leetcode contest in terms of difficulty and format. Usually, a decent score is required to advance to the interviews. If you are interested in such companies, you will need to do well in the online assessments. I will like to note that competitive programming does not prepare for the upcoming technical interviews which require other skills and preparation.

Regardless of your background, I do recommend starting on Leetcode, coding with Python. On Leetcode, there are various Explore cards where you can practice the basic concepts.

While C++ is the overwhelmingly popular language for competitive programming, I suggest learning C++ only after you started getting hit by TLEs (time limit exceeded) on Codeforces, or when you are committed to representing your school in coding competitions (e.g. NOI, IOI, ICPC).

After some exposure to competitive programming, you can determine whether are you genuinely interested in contests, or only interested in passing technical interviews, or neither. I just find coding competitions inherently fun.