Fog Creek Software
Discussion Board

How many cubes touch the face?

I was recently asked this question during an interview, and found it quite fun to solve.  I will give you a hint that I was not given:  There are two ways of visualizing the solution, and one may seem less obvious than the other.

Suppose you have a cube which is composed of n x n x n smaller cubes.  How many cubes are exposed on the outside of the structure?

Seth Morabito
Wednesday, April 14, 2004

First visual:

Number of cubes exposed on the outside of the structure
= total number of cubes - number of cubes not exposed
= total number of cubes - number of cubes on the inside
= n^3 - (n-2)^3 ,  n >= 2

Second visual:

Volume of big cube is n^3, which implies
Length of one side is n.

Surface area of big cube is 6n^2

Blocks on the 12 edges are counted twice, subtract the duplicate count from Surface area
6n^2 - 12*(n-2)

Blocks on the 8 corners are counted three times, subtract the 2 duplicate counts from previous total
6n^2 - 12*(n-2) - 2*8

which simplifies to 6n^2 - 12n + 8
which equals n^3 - (n-2)^3 as the reader can verify.

Wednesday, April 14, 2004

Exactly right.

I solved it the second way, and then the interviewer said "There's another way too," and gave me the first answer.

I think it's an interesting look into how people tackle problems, and I must say I'm a little embarassed I immediately saw the second, more complex way, but not the first, easier way.  To most people, I think the first way is more "obvious".  Apparently I like taking things apart!

Seth Morabito
Wednesday, April 14, 2004

I remember doing something like this as a GCSE maths investigation as a 15 year old or whatever.

All you need to do is think about the binomial expansion of

[(n-2) + 2]^3

the terms of that give you the number of 'corner' pieces, 'edge' pieces, 'face' pieces, and inside pieces. You then go on to generalise it to n-dimensional hypercubes and come up with a pretty formula :)

Sunday, April 18, 2004

*  Recent Topics

*  Fog Creek Home