Google Code Jam 2011: Round 1C Problem 1

Here’s another problem that appeared on the 2011 Google Code Jam: You are selling beautiful geometric pictures. Each one consists of 1×1 square tiles arranged into a non-overlapping grid. For example: .##.. .#### .#### .##.. Blue tiles are represented by ‘#’ characters, and white tiles are represented by ‘.’ characters. You do not use other [...]

Google Code Jam 2011: Round 1B Problem 1

Here’s a problem that appeared on Round 1B of Google’s Code Jam 2011 edition: Problem In the United States, 350 schools compete every year for an invitation to the NCAA College Basketball Tournament. With so many schools, how do you decide who should be invited? Most teams never play each other, and some teams have [...]

Google Code Jam 2011: Round 1A Problem 1

In order to practice for the Round 1 of Google Code Jam 2012, which is coming in two weeks, I started solving the problems of the same round of last year’s edition. Below you’ll find the first one: The Problem I played D (D > 0) games of FreeCell today. Each game of FreeCell ends [...]

Google Code Jam 2012: Qualification Problem 2

This problem was worth 20 points, and you needed to think about it a bit, but finding the answer wasn’t that difficult. The Problem You’re watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer [...]

Google Code Jam 2012: Qualification Problem 1

This weekend the qualification round of Google Code Jam 2012 took place. There were 4 problems, and you need to score at least 20 points to pass to the next round. This first problem was worth 15 points, and it was pretty trivial, so pretty much 15 free points for anyone who tried. The Problem [...]

Amazon CodeNinja Programming Contest

This Saturday the Amazon CodeNinja Programming Contest is taking place. Here’s the first problem: GIven a 2D NxN matrix, visualize it as concentric circles. You have to find the rotated matrix where each element in the circle is rotated by 1 position layer by layer in an alternate clockwise and anticlockwise direction. Input Format: First [...]

Formula For Summing A Sequence of Squares

Suppose you want to find the sum of the squares of all integers from 1 up to 200. Doing it manually would be boring a take a lot of time. Instead you can use the formula below: S = 1/6 * n * (n + 1) * (2n + 1) So in our case the [...]

How Many Different Pairs on a Tenis Tournament

Suppose you have 10 tenis players competing on your tournament, and you want to figure out in how many different pairs you can organize them so that they can play their first match. One way to calculate this is the following: First pick one player at random. Now to pick his opponent you have 9 [...]

Basics of Combinations

First make sure to read the basics of permutations. So what’s the different between permutations and combinations? Suppose we have set A = {a,b,c,d,e}. A permutation of that set could be abc, and another permutation could be acb. In other words, a permutation is an arrangement of the objects of set A, where order matters. [...]

Euclid’s Algorithm for Finding the GCD

The oldest known trivial algorithm known: int gdc (int x, int y){     int temp;     while (y!=0){         temp=y;         y=x%y;         x=temp;     }     return x; } Check the Wikipedia entry to read more about it.