Competitions and Code Jams

Given the dearth of posts lately, I’ll be the first to admit that keeping up a blog is hard – who knew that going back to school would be so busy? With midterms and finals happening pretty often, it’s taken some getting used to going from coding (and blogging) everyday to, well not.

Don’t get me wrong, you can learn to be a better coder and computer scientist without writing lots of code (I’m taking an intro to probability class for example), but there’s no substitute for it. You don’t become a better runner without actually having your shoes hit the pavement. So one of the ways I’ve tried to make sure I code often enough is to place myself in code heavy situations: coding competitions that are held on campus, entering Google Code Jam, and also doing hackathons. Here’s what I’ve learned:

1. Microsoft Coding Challenge

A few weeks ago, Microsoft came by UBC and hosted a coding competition for an evening. If you’ve never done one of these before, it’s a great experience. If nothing else, it gives you an idea of where you stand relative to other people. The format that evening was to break up into groups of three and you were then give a couple of hours and 6 problems to solve. Along with the problems, some small sample input and expected output of your solution was provided. Once time was called, you were then given 10 minutes to run large inputs using your solution code, the output of which was sent to the judge. The team that solved the most problems in the given time won cash prizes. Who doesn’t love money and the bragging rights that go along with a win?

The types of problems we had on the night varied in difficulty. The hardest one (at least if you hadn’t done it before) was writing a Sudoku solver (I doubt many people could have done this in the given time frame without having seen a solution beforehand), while the easier problems were similar in difficulty to this one from Google Code Jam where you’re given some money and the price of some items in the store, and have to find the position of the two items that will match the money you have.

My team ended up doing ok, I think I may have cost us third place with my “accidental” edit of the large input before running it through my solution (don’t do that), but it was a great experience. I learned pretty quick that my coding skills weren’t as rusty as I thought, but also that there was still quite a lot I could do to improve my placing next time around.

2. Improving your placing in a coding competition

My top tips for doing well in a coding competition:

  1. READ and understand the problem description before even thinking about writing any code
  2. It can be useful to check your understanding of the problem by manually processing (i.e. doing by hand) a sample input or two, to make sure that what you think you should be getting, is what the judges want to see!
  3. NEVER edit the large input or output. TRUST your code! One of the problems I did involved text processing and while the sample input gave me something readable, the large/test input did not. I panicked, thought I’d done something wrong, and proceeded to edit parts of the large input thinking a whitespace character had killed my program. I was wrong. My program worked just fine. Gibberish was the solution! If your code works with the sample input, it will almost certainly work with the large input! DOH!
  4. Use a high level language like Ruby or Python. You don’t want to have to worry about static typing when you’re up against the clock. The only condition to this is that if your solution is being tested against very large datasets, then a lower level language can be a lot more efficient
  5. Make sure you’re comfortable reading and writing to files. This is how you’re going to be processing input and returning output
  6. Make use of pre-written snippets of code/libraries (if allowed). Output formats for a given coding competition don’t really change from year to year and you can save valuable time by having the code which goes “Case #1: <output>” written beforehand

3. Hang on a second, how good exactly do you need to be to enter a coding competition?

To enter a coding competition, not much since entry to the qualifying round of coding competitions is mostly free and without requirement. I’d definitely encourage you to enter, no matter where you are on the coding spectrum (just make sure you’re googling and stack overflow-ing ability is up to scratch!) –  you can learn a whole lot just by entering and participating in a competition. If you solve a problem, that’ll build up your confidence and you’ll be even faster next time. If you don’t and you struggle, that’s ok too. You’re going to learn what does and doesn’t work. In Google’s main coding competition, Google Code Jam (which is open to the public – albeit registration has closed this year), you can view any user’s submissions. That means a chance to learn from the best. Reading efficient code that gets the job done (especially when you haven’t quite been able to), is a great learning tool.

Most coding competitions that are open to the public have qualification rounds which aren’t too bad so definitely check those out. Google Code Jam’s problems in the qualification round (at least the first few) are manageable as long as you know how to read to and write from a file, how to write loops.

4. Forget entering, I want to win! How good do I need to be to win competition X?

I’m no expert, having a entered a grand total of two competitions but I’d say that the best coders who win competitions like Google Code Jam (where there’s $15k as the grand prize) are good. More than good, they are practiced. Since there are only so many ways to ask coding competition questions, it becomes a case of knowing certain approaches and algorithms, and being able to apply them to slightly novel situations in the minimum amount of time. For sure, the best guys and girls out there are practicing on sites like topcoder and I wouldn’t be surprised if a lot of them have put in thousands of hours of practice to get where they are.

Most of all, I think they enjoy it. As helpful as coding competitions are for helping you get noticed in the job hunt, you don’t have to place in a competition to land a job at Google or Microsoft. It helps but it’s not a requirement. After all, coding competitions test a very particular subset of skills. Most importantly, the limited time frame of a competition is not conducive to stylistically good and well designed code – vital where the cost of maintaining the codebase for a feature far outstrips the cost of its initial creation.