Current Hiring Puzzles


You may have seen some of our programming puzzles, problems, and riddles on advertisements around Boston or on the web. They are a passion at ITA. They help us recruit technical employees who, like us, enjoy the challenge of designing and implementing solutions to fascinating computing problems.

To be considered for an interview, you may need to solve one of the programming puzzles below. A few guidelines:
 

  • Unless otherwise specified, you may use any language you like. 
  • Send your answer and resume to ita-software-puzzles@google.com. Include your source code, the final answer generated by your program, a brief (1-2 paragraph) description of your approach, and any trade-offs you made (say, for generality, speed, or ease of implementation), and instructions for testing your program.
  • No pseudo-code please! Only answers submitted by job applicants will be reviewed.

             



Want to see more?
Check out our archive of retired puzzles.

Rebus Generator


A rebus is a phrase or sentence expressed all or in part through pictures. For this puzzle, you will use pictures from this archive (use the included file "images.txt" to map pictures to the associated words). Write a program that will take an English sentence (here’s a list of test cases for you to use) and generate a rebus from it. Here’s a simple example:
 


That is, each word becomes a parenthesized expression with up to three components: a word corresponding to a picture from the clipart library, a sequence of letters to be added to the name of the picture, and a sequence of letters to be deleted from the name. Distinguish words used as pictures from other sequences of letters by prepending a colon. The order of letters must match: the letters to be added must be in the order in which they would appear in the target word, and the letters to be deleted must be in the order in which they appear in the image name. Your program should produce plain text output.

But there’s more to the puzzle than that. Suppose we charge 5 points for every consonant you add or delete, and 1 point for every vowel. Now come up with a rebus that costs the fewest points. The example above costs 57 points, but this rebus of the same phrase:

costs only 31 points.

Finally, you can reduce the cost even further by adding or subtracting images (which cost nothing) instead of letters. If you use recursive encodings, you can get rid of letters altogether. For instance, a recursive rebus for “solve” is:
 

 
Write a program to generate recursive rebuses like the one above. Your program may use a mix of letters and pictures; balance performance against optimal scores as you see fit. Even for all-picture rebuses, a shorter rebus is better.

 

Optimal Ghost


In the game of Ghost, two players take turns building up an English word from left to right. Each player adds one letter per turn. The goal is to not complete the spelling of a word: if you add a letter that completes a word (of 4+ letters), or if you add a letter that produces a string that cannot be extended into a word, you lose. (Bluffing plays and "challenges" may be ignored for the purpose of this puzzle.)

Write a program that allows a user to play Ghost against the computer.

The computer should play optimally given the following dictionary: WORD.LST (1.66 MB). Allow the human to play first. If the computer thinks it will win, it should play randomly among all its winning moves; if the computer thinks it will lose, it should play so as to extend the game as long as possible (choosing randomly among choices that force the maximal game length).

Your program should be written as a Java web application that provides an html-based, rich GUI for a human to play against the optimal computer player from inside the Firefox browser. The web page should access a server using JavaScript's XMLHttpRequest object, and display the results using DOM manipulation. Your GUI does not have to be complicated, but should be polished and look good.

Please submit your source code, configuration instructions, and any comments on your approach. Please also include a WAR file that we can test against Tomcat 5.5.x on Sun's J2SE 6.0. Finally, in your submission email, answer this question: if the human starts the game with 'n', and the computer plays according to the strategy above, what unique word will complete the human's victory?  
 

BitVector Genealogy


The BitVectors are an ancient and immortal race of 10,000, each with a 10,000 bit genome. The race evolved from a single individual by the following process: 9,999 times a BitVector chosen at random from amongst the population was cloned using an error-prone process that considers each bit independently, and flips it with 20% probability.


Write a program to guess the reproductive history of BitVectors from their genetic material. The randomly-ordered file bitvectors-genes.data.gz contains a 10,000 bit line for each individual. Your program's output should be, for each input line, the 0-based line number of that individual's parent, or -1 if it is the progenitor. Balance performance against probability of mistakes as you see fit.


To help you test your program, here is a much smaller 500 x 500 input dataset:bitvectors-genes.data.small.gz, along with its solution file: bitvectors-parents.data.small.
 

Instant Search


Write a Java web application which provides "instant search" over properties listed in the National Register of Historic Places. Rather than waiting for the user to press a submit button, your application will dynamically update search results as input is typed. We provide the file nrhp.xml.gz, which contains selected information from the register's database.

Database
The key component of your server-side application is an efficient, in-memory data structure for looking up properties (written in pure Java). A good solution may take several minutes to load, but can answer a query in well under 0.1 ms on a modern PC. (Note that a sequential search of all properties is probably too slow!) An input matches a property if it is found at any position within that property's names, address, or city+state. Matches are case-insensitive, and consider only the characters A-Z and 0-9, e.g. the input "mainst" matches "200 S Main St" and "red" matches "Lakeshore Dr." Note that the server's JVM will be configured with 1024M maximum heap space. Please conform to the interfaces specified in nrhp.jar when creating your database.

Servlet
Your servlet should accept an input string as the request parameter to a GET request. Results should include the information for a pre-configured number of properties (e.g. 10), the total number of matches which exist in the database, and the time taken by your search algorithm. Your servlet should be stateless, ie. not depend on any per-user session information. Paginate your additional results as a bonus!


Client
Your web page should access the servlet using JavaScript's XMLHttpRequest object. As the user types, your interface should repeatedly refine the list of search results without refreshing the page. Your GUI does not have to be complicated, but should be polished and look good.
 

Please submit a WAR file, configuration instructions, your source code, and any comments on your approach. Your application will be tested with Tomcat on Sun's 64-bit J2SE and a recent version of Firefox.
 

Resources XMLHttpRequest, StAX, Apache Tomcat, Mozilla Firefox, Eclipse
 


 

Roll Your Own Chat Server


Implement a simple standalone TCP-based chat server, using the following protocol:

The server responds to all commands with either:
						OK<CRLF>


or, when an error occurred, with:
						ERROR <reason><CRLF> 


<CRLF> indicates the bytes '\r\n'.

Upon connecting to the server, the client sends:
						LOGIN <username><CRLF> 


Clients can create new chatrooms or join existing chatrooms (chatrooms begin with the character '#') by doing:
						JOIN #<chatroom><CRLF>


Clients can leave chatrooms by sending:
						PART #<chatroom><CRLF>


Clients can be in multiple chatrooms at once.

Clients can send a message to a chatroom:

						MSG #<chatroom> <message-text><CRLF> 


Clients can send a message to another user:
						MSG <username> <message-text><CRLF>  


When a message is sent to a chatroom the user is in, the server sends to the appropriate client:
						GOTROOMMSG  <sender> #<chatroom> <message-text><CRLF> 

or if the message is sent directly from one user to another:
						GOTUSERMSG <sender> <message-text><CRLF>  


Finally, the client can log off by sending:
						LOGOUT<CRLF>

Here's a transcript of a sample session where a user named "alice" joins a chatroom called #news after connecting. C indicates the line was sent by the client, S indicates it was sent by the server (end of line indicates CRLF was sent):


C: LOGIN alice

S: OK

C: JOIN #news

S: OK

C: MSG #news hi everyone

S: GOTROOMMSG bob #news nothing much happened after that

S: OK

S: GOTROOMMSG alice #news hi everyone

S: GOTUSERMSG carol hi alice, where've you been?

C: MSG carol on vacation

S: OK

C: LOGOUT



When implementing the server, aim for scalability and robustness. (Many submissions fail due to lack of robustness!) Your submission should include a description of the steps you took towards those two goals. Keep in mind that the client may be buggy, or even malicious. For example, if a client connects to the server and sends an infinite stream of the byte 'X' with no line break, the server should deal with this case gracefully. Please do not use an existing networking framework (e.g., Twisted or asyncore for Python, ACE for C++, etc.) to implement the server. The server should support running on Linux. 
 

 

The O'Hare Affair


Objective
You want to meet a friend at O'Hare airport at noon and return home the same day. Given a date and an origin airport, find the pair of nonstop flights that gets you to Chicago and home again on that date, minimizing your total time away from home, subject to the constraint that you are at O'Hare at noon. 


Details
Your program, which must be written in Java, will work by scraping our http://matrix2.itasoftware.com website. Your program should accept two command-line inputs as follows: 

java -jar OHareAffair.jar YYYY-MM-DD airportCode


The program should navigate to matrix2.itasoftware.com and pose a round-trip query between the given airportCode and O'Hare (ORD), limited to nonstop flights only, using BOS as the sales city, with appropriate date and time constraints. The program should then scan the resulting solution set for solutions that meet the objective specified above. No more than 15 http requests should be made of matrix2.itasoftware.com per invocation. Finally, details of the three shortest solutions (breaking ties arbitrarily) should be written out in human-readable form to the console.


For example, for a traveler from Baltimore on July 4th, your program might be invoked as follows: 


java -jar OHareAffair.jar 2006-07-04 BWI


Sample output:


Travelling round-trip from BWI to ORD on 2006-07-04:
Trip length: 6:21
Outbound: American Airlines Flight AA3991 (10:03a-11:04a)
Return: United Airlines Flight UA1236 (1:30p-4:24p)
Trip length: 6:39
Outbound: United Airlines Flight UA641 (9:45a-10:47a)
Return: United Airlines Flight UA1236 (1:30p-4:24p)
Trip length: 6:54
Outbound: American Airlines Flight AA3991 (10:03a-11:04a)
Return: American Airlines Flight AA4009 (2:09p-4:57p)


Strive to make your code clean and robust, and to report errors cleanly. Be sure to include your source, any necessary libraries, and instructions on how to run it. 

 

Strawberry Fields


Strawberries are growing in a rectangular field of length and width at most 50. You want to build greenhouses to enclose the strawberries. Greenhouses are rectangular, axis-aligned with the field (i.e., not diagonal), and may not overlap. The cost of each greenhouse is $10 plus $1 per unit of area covered.

Write a program that chooses the best number of greenhouses to build, and their locations, so as to enclose all the strawberries as cheaply as possible. Heuristic solutions that may not always produce the lowest possible cost will be accepted: seek a reasonable tradeoff of efficiency and optimality.

Your program must read a small integer 1 ≤ N ≤ 10 representing the maximum number of greenhouses to consider, and a matrix representation of the field, in which the '@' symbol represents a strawberry. Output must be a copy of the original matrix with letters used to represent greenhouses, preceded by the covering's cost. Here is an example input-output pair:

Input   Output
4
..@@@@@...............
..@@@@@@........@@@...
.....@@@@@......@@@...
.......@@@@@@@@@@@@...
.........@@@@@........
.........@@@@@........
                  90
..AAAAAAAA............
..AAAAAAAA....CCCCC...
..AAAAAAAA....CCCCC...
.......BBBBBBBCCCCC...
.......BBBBBBB........
.......BBBBBBB........

In this example, the solution cost of $90 is computed as (10+8*3) + (10+7*3) + (10+5*3).

 

Run your program on the 9 sample inputs found in this file and report the total cost of the 9 solutions found by your program, as well as each individual solution.

 

Word Rectangle


Write a program to find the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). Words should appear in this dictionary: WORD.LST (1.66MB). Heuristic solutions that may not always produce a provably optimal rectangle will be accepted: seek a reasonable tradeoff of efficiency and optimality.