Programming Contest Tips
Recently I participated in a few Programming Contests: Garmin Programming Competition 2014, ACM programming contest at Kansas State University and Google Code Jam 2014. I also remember my first contest in algorithms KPI-Open 2011, in Kyiv, Ukraine. It was for teams of up to 3 people. There were 16 problems to solve during the 2 days. We solved one.
In some contests, there is no access to the Internet. It was the case during my first contest (KPI-Open 2011). We were able to use Java, C++ or Pascal. The first problem we faced was: "HOW TO READ INPUT FROM CONSOLE IN JAVA?". None of us remembered. Fortunately, we knew how to do it in C++. Thus we had to use C++ for the first day. We were more proficient in Java though and it slower our development. Before day two, we created a cheat-sheet (we could bring as many printed papers as we wanted) with reading input in Java and some other tricks, which you usually google for. It allowed us to solve one problem. By solving problems I mean, delivering solutions, which pass tests in the required amount of time. We solved 7-8 problems (or even more?) during those two days, but only 1 got accepted. It gave us 64 places (among 83 teams).
A few months after that, I participated in ACM programming contest at Kansas State University with one friend of mine. There was progress: 1 problem was solved in 5 hours (1 day). It is better than 1 problem in 2 days :) Last year, I was 1-person team, and I got 3 problems solved (I was somewhere around 6-10 place). This year: I also solved 3 problems, but it gave me 3rd place.
Last year, I was also participating in Google Code Jam. In this contest, you just need to deliver solutions for a given input. You download the input file from the website and you have some amount of time to upload the solution (usually up to 10 minutes). Additionally, in most problems, there is a small input set and a large input set. The large set has more test cases and/or bigger numbers (e.g. integer is not enough to solve it).
The most important thing during the Programming Contests is time. Time, in which you solve the problem.
My general tips (based on competitions I participated in) on how to prepare for programming contests:
- Make preparation before. Do not just walk in (especially if it is your first contest). Check Programming Contest Year Plan - Yes a year Plan to be a better Programmer.
- Take Introduction to Algorithms book to the contest.
- Create (and print if no internet access is allowed) a template for the standard program. 90% of problems have N test cases. You need to parse it, compute the solution and print it. My approach is to read all input first and serialize it to e.g. Case class. Then I am looping through all cases and printing output. I prepared a template file, which allows me to save time during the contest.
- Find out what languages/technologies are allowed during the contest and practice with it before the contest. Programming in Eclipse is different than programming in Visual Studio! Especially debugging.
- Find out how you need to provide a solution (send source code or just solution?) and how to read/write input/output.
- If possible, find problems from previous editions of a particular contest and practice by solving them.
- Don't be afraid to write bad code. You don't need to comply with the best practices. It doesn't matter, whether your code is not SOLID. Your code is not readable? Who cares? Don't waste time refactoring. If you feel bad about the code you have written - refactor it after the contest. The only thing, which matters is, whether it solves the problem efficiently. Check solutions of the best competitors at Google Code Jam World Finals 2013. Can I write better code? Sure I can. But nobody cares, because they (not me) were the best in last year's contest.
Solving algorithmic problems is only part of programmers' skills toolset. If somebody is not good at it, it does not mean he is a bad programmer. He may be good at something else (e.g. programming embedded devices for aircraft or designing the rocket system). However, it is good to practice problems solving and writing code. It is like a daily workout. The programmer who wrote 1000 programs will be always better than one who wrote only 10. You will definitely become a better programmer with programming challenges.
My code for ACM contests and Google Code Jam is available on GitHub: