Zynga Interview Question for Software Development Managers


Country: United States
Interview Type: In-Person




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

I reduced my equation to 6n^2 - 12n + 8.

6n^2 is number of sub cubes w/o accounting for overlapping sides and corners.

Subtract 12n, 12 is the number of sides and n is the length of each side. Each side is accounted for twice in 6n^2.

Subtract 8, the number of corners, which are accounted for 3 times in 6n^2.

- rob September 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

I get the same answer as rob but I start out a little differently, rather then thinking about just the 6 faces and then subtracting edges for other face pairs as mentioned by rob you can calculate the volume of the cube and then subtract the volume of a cube that is one layer smaller i.e. fit inside the problem cube.

Note that if n == 1 then the answer is 1
for n > 1 -> outer sub cubes = volume of cube - volume of inner cube
= n^3 - (n-2)^3

this simplifies to 6n^2 - 12n + 8

- AMP September 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

why (n-2)^3 it should be (n-1)^3 i guess

- GauravK December 19, 2015 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

// Given a cube made of N x N x N sub-cubes, how many sub-cubes are
// on the outside of the cube?

// Consider the trivial case N = 1, the answer is 1.
// Consider the next trivial case N = 2

// The answer is 8 because the 2x2x2 cube is comprised of only 
// 8 subcubes, 1 @ each corner.

// Consider N = 3, we have 8 corner cubes, plus 1 cube in the 
// center of each of the composite cube's 6 faces, plus 1 cube 
// extra along the length of each of the main cube's 12 edges.

// Consider N = 4: 8 corner cubes, plus 4 cubes in the center
// of each face, plus the cubes between the corners on each of 
// the 12 sides is 2.

// It turns out that this can be described by the following 
// equation:

// ƒ(N) = 8 corner cubes + (6 faces * (N - 2)^2) + 12 sides * (N - 2)

"use strict";
module.exports = function (N) {
	let sides = 0;

	if (N === 1) {
		sides = 1;
	} else if (N > 1) {
		sides = 8 + (6 * Math.pow(N-2, 2)) + (12 * (N - 2));
	}
	return sides;
};

- srterpe September 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

cube has 6 faces, each has n*n subcubes on each face. so from top and bottom 2n^2+4(n-1)

- Harsha A C September 29, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not quite but you seem to be on the right path. It looks like you tried to account for the 4 remaining sides with 4(n-1), which isn't correct.

By the way, what the interviewer also looked for is whether I was able to reduce the equation down to the simplest terms.

Note this interview I had was 2 years ago.

- lindat September 29, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

(N+2)^3 - N^3 => 6n^2 - 12n + 8.

- Hammad September 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about n^3 - (n-2)^3

- AAAA September 30, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The way to solve this problem is to realize that for a cube to be contained inside another it has to be placed right in the middle, thus it has to measure two units less than the big cube (N-2) so it can fit.

Picture now the number of cubes (the volume) that will not "see the light" (N-2)^3 subtract this from the total N^3 and you'll have your "shell volume".

Very harsh question to ask under pressure and in the context of an interview... I guess there are worst things in life, so just do your best.

- Rx777 February 12, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Method 1:
lowermost layer = n*n
uppermost layer = n*n
in between = (n-2)*(4*(n-1)) = (n-2)*(4n-4)=4*n*n -12n +8

Total = 6*n*n -12n +8

Method 2:
Total exposed cube surfaces on one flat surface = n*n
Total exposed cubes surfaces on 6 flat surfaces = 6*n*n ---(1)
No. of surfaces having another exposed surface in its cube twice or more times = No. of edges * cubes/edge = 12 * n ---(2)
No. of surfaces having 3 exposed surfaces in it's cube = No. of cornwes =8 ---(3)



Total no. of exposed cubes = (1) - (2) + (3)
= 6*n*n -12n +8

- neerajlakhotia08 February 28, 2017 | 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