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.
there are 6 sides, 12 edges, and 8 corners
ReplyDelete6(N/n-2)^2 + 12(N/n-2) + 8
Number of building-blocks on surface of any given face = K^2
ReplyDeleteNumber of faces = 2*KC2 = K*(K-1)
Number of blocks on outer faces = K^3 * (K-1)
2^1*kC1*(n-2)^k-1 + 2^2*kC2*(n-2)^k-2 + ... + 2^k*kCk*(n-2)^0
ReplyDeleteno of cubes on the surface = k^3 - (k-2)^3
ReplyDelete(k-2)^3 is the cube which is enclosed by the surface.
Umm... why the roundabout way?
ReplyDeleten^3 - (n-2)^3 (outer minus inner)
so with dimensionality = k,
n^k - (n-(k-1))^k
Correct Answer is:
ReplyDeleteK^3 - (k-2)^3
above to above solution is correct..i agree to it
ReplyDeleteThe Correct answer is
ReplyDeleten^k - (n-2)^k for k dimensions