-1

Studying up for interviews and going through these questions.

8.Given a cube of size n*n*n (i.e made up of n^3 smaller cubes), find the number of smaller cubes on the surface. Extend this to k-dimension.

I don't understand the question very well. For one side, we'll have n^2 number of cubes on the surface. And there are 6 sides on a cube, so is the answer just 6n^2? That seems too simple to me. Any help would be appreciated.

jb.
  • 9,921
  • 12
  • 54
  • 90
  • 2
    Your solution counts cubes more than once. Remember that cubes on an edge will have faces on up to two other sides. – Matt Eckert Apr 11 '12 at 22:21
  • @mteckert good point, so for two sides we have the entire side. for the other four we don't count the edge cubes. so it's `2n^2 + 4(n-2)^2`. Does that look right? – jb. Apr 11 '12 at 22:33
  • Visualize a Rubik's Cube. Only one of the smaller cubes is unexposed to the surface. From this information, you can see your equation does not hold for 3x3x3. (Hint: do two entire faces account for *all* the edge cubes on the remaining faces?) – Matt Eckert Apr 11 '12 at 22:58
  • 1
    @mteckert of course you are right again. Let's go about it the other way, what is not on the surface? For 3x3x3, one is in the middle. For 4x4x4, 2^3 are in the middle. so is it `n^3 - (n-2)^3` in other words `all - middle`? – jb. Apr 11 '12 at 23:03
  • Yes! This is probably the solution James Black was hinting at. – Matt Eckert Apr 11 '12 at 23:11
  • @mteckert nice, thanks for the help. If you make an answer, I'll accept it. – jb. Apr 11 '12 at 23:16
  • You can post it yourself and accept it, since it was you who came up with it. (This is fine/encouraged on SO) – Matt Eckert Apr 11 '12 at 23:20
  • @jb - Congrats on figuring out the solution. – James Black Apr 12 '12 at 00:02

2 Answers2

2

If you have a cube that is 4x4x4, so it would contain 64 cubes of size 4, how many of these cubes are on the surface?

I would do it for 3 and 4, then come up with an equation, and test with 5.

Basically, how many of the cubes don't touch the surface is another way to look at it.

James Black
  • 41,583
  • 10
  • 86
  • 166
1

There are n^2 1*1*1 cube in one side, but there are (n-1)^2 2*2*2 cube in each side and ... 3*3*3, ...

Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83