Cracking the Coding Interview: Fourth Edition (308 page e-book / PDF)
Delivered instantly as a PDF via email. For Software Engineers & SDETs
  • 150 programming interview questions and answers
  • 5 proven approaches to crack algorithm questions
  • 10 mistakes candidates make, and how to avoid them.
  • How to prepare for technical and behavioral questions without wasting your time!
"The BEST book for acing your interview. It helped me land my Microsoft job, and it was worth every penny!" - Ravi (Accepted at Microsoft, Amazon and Facebook) 30 Day Money Back Guarantee: Don't love the book? We'll give you your money back! More Info

Saturday, April 24, 2010

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.

8 comments:

  1. there are 6 sides, 12 edges, and 8 corners

    6(N/n-2)^2 + 12(N/n-2) + 8

    ReplyDelete
  2. Number of building-blocks on surface of any given face = K^2
    Number of faces = 2*KC2 = K*(K-1)
    Number of blocks on outer faces = K^3 * (K-1)

    ReplyDelete
  3. 2^1*kC1*(n-2)^k-1 + 2^2*kC2*(n-2)^k-2 + ... + 2^k*kCk*(n-2)^0

    ReplyDelete
  4. no of cubes on the surface = k^3 - (k-2)^3

    (k-2)^3 is the cube which is enclosed by the surface.

    ReplyDelete
  5. Umm... why the roundabout way?
    n^3 - (n-2)^3 (outer minus inner)
    so with dimensionality = k,
    n^k - (n-(k-1))^k

    ReplyDelete
  6. Correct Answer is:

    K^3 - (k-2)^3

    ReplyDelete
  7. above to above solution is correct..i agree to it

    ReplyDelete
  8. The Correct answer is

    n^k - (n-2)^k for k dimensions

    ReplyDelete