Interview Questions

Suppose you are given a cube and each face of the cube contains an array. ....

Microsoft Interview Questions and Answers


(Continued from previous question...)

99. Suppose you are given a cube and each face of the cube contains an array. ....

Question:
Suppose you are given a cube and each face of the cube contains an array of size N X N. You need to print the entries of this cube in a SPIRAL ORDER.

1) How would you define a spiral in above case such that there is no collision between each layer of the Spiral?

2)How will you store the above structure i.e. cube?

3) Write the code for the same.


maybe an answer:


Defined the definition of spiral as matrix at face 6 then 1,2,3,4,5. So it is nothing but a matrix of row = n and column = 6n.

So now it is the same code as printing a matrix in spiral fashion. I think the only twist is that the matrix on which u will do the operation will be of size (n,6n)

Define the matrix in any order like 1,2,3,4,5,6; because he as asked us to define that.

Define the cube class as follows: The class cube can have square[6] as data member. class Square can have edge[4] as data member. Class edge can have Points[2] as data member. Class Point can have x and y as data members.

(Continued on next question...)

Other Interview Questions