Amazon Interview Question






Comment hidden because of low score. Click to expand.
1
of 1 vote

One solution from Stack overflow:
--------------------------------------------
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

- Anonymous January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

should there be method that will give the user the current state of the entire cube. so that he can make the next rotation depending on that.

- isandesh7 January 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

- hprem991 January 29, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More