Google Interview Question
InternsCountry: United States
Interview Type: Phone Interview
What do you mean by backend database portion? Since a cube has 6 faces, each face has 9 squares, can we just represent it by an array that's 54 items in length?
a[i] can have color of the element i.
(Using 1 as starting index for simplicity) a[1-9] = face1, a[10-18] as face2 and so on.
I agree, why do we need a database for this? A simple array of "face" objects with color property should do the trick, no?
You are counting only the squares that are the outside of the cube which is (6x9)= 54. What about the sides hidden inside the cubes and that will come out when we rotate the the cubes?
A 3x3x3 cube has 26 sub cubes on outside. And Each sub cube has 6 distinct colors (sides). We need to design a data structure that represents all sides of the sub cubes and the current outer side of each sub cube.
Since they asked Rubiks cube I believe we can leave out the center 1/ 27 cube. Basically we divide a cube into
6 centers
8 corners
12 edges
But this is only the numbers of squares
visible now we have to account for filling the six colors.
So an array of (3x3) x6 should be sufficient to hold a cube configuration.
with reference to stackoverflow 500221. here is a DS
- jitendra.theta January 16, 2014