Country: United States
Interview Type: Phone Interview

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

with reference to stackoverflow 500221. here is a DS

``````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``````

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

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.

Comment hidden because of low score. Click to expand.
0

I agree, why do we need a database for this? A simple array of "face" objects with color property should do the trick, no?

Comment hidden because of low score. Click to expand.
-2

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.

Comment hidden because of low score. Click to expand.
0

@Anonymous about hidden cubes: What? LOL.

Comment hidden because of low score. Click to expand.
0
of 2 vote

For a 3x3x3, we have 27 smaller cubes

1 at the center, no color
6 at the center of each face, 1 color
8 corners, 3 colors
Remaining 12 with 2 colors

That sums up to 54.

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

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.

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.

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.