Archive for July 23rd, 2011

July 23, 2011

Interview Question: Flipping Switches

by Mikael

This came up a long time ago, I only recently recalled it:

Consider a sequence of 100 switches all initially set to “off”. Flip every switch. Now starting with the first switch, flip every second one (i.e. #0, #2, #4, …). Then, starting again with the first, flip every third switch (i.e. #0, #3, #6, …). Proceed in that manner, always starting with the first switch, switching every fourth, then fifth, then sixth switch etc.. Once the first switch has been flipped a hundred times, which switches are set to “on”?

read more »

Advertisements
July 23, 2011

Interview Question: Data Structure for Tic-Tac-Toe

by Mikael

Got this recently:

Tic-Tac-Toe decision tree

Tic-Tac-Toe decision tree

How would you design a data structure for the game Tic Tac Toe? The main objective is to provide: A method, as efficient as possible, for checking the board to see if there is a winner.

read more »