Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
1
of 1 vote

Datastructure is a struct of the below form

struct Node {
 Image value;
 Node *left,*right,*top,*bottom;
};

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:

1) for each piece B
  a) if 1st piece, initialize node and continue
  b) for each node A that is already created
     i) call isNeighbor(A,B)
2) The only node that does not have a top and left pointers set is the top left corner square, and from it we can traverse the picture.

- IntwPrep December 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

- ashot madatyan June 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't think that's the point of this question. I think you're only given the pieces as pixels.

- Anonymous June 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- ashot madatyan June 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

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.

- eugene.yarovoi June 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@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?

- ashot madatyan June 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yep. And you're usually asked to do this as efficiently as you can, given that the number of pieces could be large.

- eugene.yarovoi June 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

those 16 squares are not EQUAL ones... one may be big and another one may be smaller. is that correct?

- Anonymous June 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@tulip:What was your answer?

- Anonymous June 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

There are 16 squares shuffled so we can
consider them as 0 to 15 numbers.
Hence we only have to write a program for number sorting
or
We can also consider it as matrix and can write a program in that way

- Rahul June 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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 !!

- softy July 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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.

- ravi June 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not true. Consider a counterexample where you have a 9x9 square formed from a 6x6 and 5 3x3s.

- eugene.yarovoi June 18, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More