### Competitive Programming as a Sport

**Vichitr**- 30 Dec 2018

Exploring and understanding competitive programming.

Competitive programming is a mind sport usually held over the Internet or a local network, involving participants trying to program according to provided specifications.

– Anonymous.

People enjoy playing sports like Cricket, Football, Badminton etc., but there is a community of programmers who enjoy playing with their codes. This sport is called Competitive Coding/Programming. The difference between other sports and competitive coding is that you don’t require a lot of physical activity in competitive coding. Now-a-days coding is used in almost every field of work directly or indirectly. It’s not just the need for tech companies, but of each and every business. From accountants using spreadsheets to artist and designers using graphics software, everyone needs coding in some way. All major tech companies like Google, Facebook etc hire top coders. Coding is one of the most demanded skills today. Competitive coding is a form of coding as a sport. Many people do it just for fun, to enjoy it, while others do it to get a good paying job in the tech industry.

In the sport of competitive coding, participants are given some problems to solve and are required to write code in any acceptable programming language. The problems are generally logical or mathematical. However, participants may require the knowledge of algorithms, data structures, number theory, geometry, graph theory or any other related topic to solve the problems. Competitive coding has a very large community including school and college students. It is all about thinking quickly to understand the problem and break down into the most optimal way possible and write the code in a programming language. In the very beginning, people get demotivated when they don’t get their solution accepted. But believe me, don’t let yourself down and keep trying, you will start feeling the pleasure of accepted solutions. Many people like me, do it just for that satisfaction of getting their solution accepted. In my opinion, this is the best sport everyone should at least try.

Why one should try competitive coding? Competitive coding may not be the ultimate coding practice to write good and well-documented code, to make optimum use of memory and other resources, to work in an organizational environment. But if you are good at it, learning other things will be a piece of cake for you. You can easily crack standard coding interviews, you can easily solve a programming problem or puzzle given during an interview. In the sport of competitive coding, you get the habit of solving challenging problems and you do not give up easily. Also, competitive coding improves your debugging skills. If your code fails to get accepted, you need to think where it went wrong. This also improves your thinking skills. While participating as a team, you also learn to think, code and debug as a team which is the most important skill required in the industry today. Although competitive coding does not involve any other aspects of programming like Networking, Cryptography, Artificial Intelligence, Machine Learning etc., it improves your knowledge of algorithms and data structures tremendously and develops your thinking, logical and analytical skills which are otherwise hard to instil. You can also win prizes like t-shirts or goodies or even cash in the contests.

Most prestigious coding contests are ACM-ICPC, Google Code Jam, Facebook Hacker Cup, TopCoder Open, Codechef SnackDown and IOI. IOI (The International Olympiad in Informatics) is an annual international competitive programming contest for secondary school students while ACM-ICPC is an annual international competitive programming contest for collegiate students. These competitions are usually held on online judges. Some of the popular online judges which conduct contests regularly are – Codeforces, Codechef, HackerEarth, AtCoder, TopCoder, Hackerrank. To compete in coding contests, you need good knowledge of a particular language, preferably C++/Java/Python. C++ is the choice of a majority of competitive programmers as it is fast and has a nice STL tool. I will describe some of the platforms mentioned above.

Codeforces:

This is the best available competitive coding platform today. It conducts 2-3 contests every week. It is known for regular contests. All codeforces contests contain very good problems. Mostly all contests are balanced on Codeforces. It also conducts Codeforces Educational Rounds. Goal of such rounds is to practice and educate rather than to compete.

Codechef:

Codechef is also a good platform to learn and compete competitive coding. It conducts three contests each month – Long challenge, Lunchtime, Cook-off. Long challenge is meant to learn a lot of new concepts as it’s a 10-day long contest. Codechef problems mostly require very much thinking and debugging. You should keep trying.

HackerEarth:

HackerEarth also conducts three contests every month – Easy, HourStorm and Circuits. HackerEarth problems are damn good if you want to learn. But most of the times, problem statements are not clear. Circuits is an 8-day long contest so you can learn and try.

Hackerrank:

If you want to start coding then this is best platform to start with. Hackerrank problems are usually easy and simple. It conducts HourRank every month. And two other contests – Week of Code, Codesprint are held over a period of 2 to 3 months.

AtCoder:

This is a famous Japanese judge. AtCoder problems are usually mathematical. It conducts three contests – ABC(AtCoder Beginner Contest), ARC(AtCoder Regular Contest) and AGC(AtCoder Grand Contest). AGC is held once a month. ABC and ARC are held 2-3 times every month.

TopCoder:

Topcoder is not a cup of tea for everyone. As its design is very confusing and participants are required to write Class and Method to solve a problem instead of whole code. But its problems are very good. Most of topcoder problems are DP(Dynamic Programming) problems so if you want to master DP then give a try to topcoder. It conducts 2-3 SRMs every month.

Except from these, CS Academy is also a good platform to compete. It conducts 1 contest per month hardly. But csacademy problem statements are very short and clear without any story. Other than these, some platforms which does not conduct contests but have a lot of good problems to try and learn are – SPOJ, UVa Judge.

SPOJ: It’s a problem Archive (recommended for all beginners). Start with problems having maximum submissions. Solve first few problems (may be 20). Build some confidence. Then start solving problems topic wise. Never get stuck for too long in the initial period. Google out your doubts and try to sort them out or you can discuss with someone (ONLY IN THE BEGINNING).

These are some topics to start with –

- Arrays, Strings
- Basic math operations (addition, subtraction, multiplication, division, exponentiation)
- Bitwise operations
- Searching (Linear and Binary) and Sorting
- Basic Recursion
- Euclid’s GCD algorithm
- Sqrt(n) primality testing
- Greedy algorithms
- Basic data structures – Stack, Queue
- Prime Numbers, divisibility of numbers, factorization of a number

Some advanced topics are –

- Sieve of Eratosthenes
- Modular Arithmetic – division, inverse
- Divide and Conquer
- Dynamic Programming
- Heaps
- Segment Tree
- Binary Indexed Tree
- Disjoint Set Union
- Suffix Arrays
- Trie
- Tree traversal
- Lowest Common Ancestor (LCA)
- DFS, BFS
- Shortest path algorithms – Dijkstra, Bellman-Ford, Floyd-Warshall
- Minimum Spanning Tree – Prim’s and Kruskal’s algorithms
- Biconnectivity in undirected graphs – articulation points and bridges
- Strongly connected components in directed graphs
- Topological sorting
- Euler path/tour/cycle

Once you have a good catch and confidence, dive into the world of competitive coding and start participating in regular contests on Codechef, Codeforces etc.

**HAPPY CODING!!!**

**Vichitr Gandas on 30 Dec 2018**