Amazon Interview Question
Now this is really a Great question..
My Approach would have been as follows.
1> Class Cube contains.. Following methods
A> Rotate which contains two parameters and return success or failure.First the direction of rotation and second the number of rotation. Direction is a enum with up/down and right/left value.
B> Verify which contains two parameters and returns where position it mismatched. First the position of a piece and second the array of number of surroundings pieces(For centre key it will contain 8 or maximum value in the array). You can calculate the color of the particular piece by using another method.
C> Color which will have again two parametes and returns the color type.The piece position and the face on which the piece lies. For reference we can name faces as 1 to 6.
One solution from Stack overflow:
- Anonymous January 29, 2013--------------------------------------------
class Square
+ name : string
+ accronym : string
class Row
+ left_square : square
+ center_square : square
+ right_square : square
class Face
+ top_row : list of 3 square
+ center_row : list of 3 square
+ bottom_row : list of 3 square
+ rotate(counter_clockwise : boolean) : nothing
class Cube
+ back_face : face
+ left_face : face
+ top_face : face
+ right_face : face
+ front_face : face
+ bottom_face : face
- rotate_face(cube_face : face, counter_clockwise : boolean) : nothing