Google Interview Question for Interns


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

- jitendra.theta January 16, 2014 | Flag Reply
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.

- Teja December 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Anonymous December 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

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.

- Anonymous December 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous about hidden cubes: What? LOL.

- Anonymous December 28, 2013 | Flag
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.

- Arth December 29, 2013 | Flag Reply
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.

- Rishi December 31, 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