Microsoft Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
Just enumerate (assign consecutive numbers to) each of the 16 small squares and use the square numbers to rearrange them to get the original picture. In this case, each of the small square would have numbers 0-15.
I don't think that's the point of this question. I think you're only given the pieces as pixels.
Well, it depends upon what the problem means by "16 squares", how do you define them and use (e.g. how do you shuffle those small squares). Anyway, the solution that I have provided does not break anything in the original problem description. Maybe, the problem shall be defined more clearly in terms of DS's and use cases.
I don't imagine there are many scenarios where you're asked to solve a puzzle just by tagging the pieces before they're scrambled. This sounds like a classic interview question where you're asked to make this reconstruction from the pixels, provided that every edge is duplicated so that you can figure out how to fit the pieces together.
@Evgeny.
Thx for clarification, your definition of splitting the image is much more elaborate than the original. So, do you mean that each neighboring square shares a single vertical/horizontal line of pixels?
can it be done someting like this :
(1) Take an array of 16X4 , 4 edges of 16 squares
edges will be : left,right,top, bottom
fill the array with the 16 elements.
(2) Define a Data Structure which has not only left and right child but also top and bottom child as well , now define an function just like inserting node in linked list (but here you have to insert all the adjacent edges) and search for the adjacent square edge and build the data structure.Searching of adjacent square can be done by iterating over each square and comparing the edges,
e. char edges[16][4] = { {ab,bg,gf,fa},{bc,ch,hg,ga},{cd,di,ih,hc},....}
where the square is like this
a__b__c__d__e
|f__g__h___i__j
|k__l__m__n__o
|p__q__r__s__t
|u__v__w__x__y
different squares are - abgf,bchg,cdih,deji,
square abgf and bchg has left common that is bg , similarly every two adjacent square will have either left,right,top or bottom edge same.
does it makes some sense !!
I think if a square picture is cut down into 16 small square then all the small square will be same in area.There is no any possibility that some would be small and some would me large.
Datastructure is a struct of the below form
Assumption: existence of a method isNeighbor(Node *A, Node *B) which checks if B is the neighbor of A and assigns the A's pointer accordingly
Algorithm:
- IntwPrep December 04, 2013