Microsoft Interview Question for Software Engineer / Developers






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

First you need a "Piece" class to represent one piece of a puzzle.
Each piece has four sides, each one with a unique outline which will
only connect to one other piece. Edge sides have an "edge" outline.
Each side also has a piece id attribute called "adjacent" to store the
value of the piece it connects to. Piece provides a "rotate" method
which turns the piece 90, 180, or 270 degrees.
The "Jigsaw" class has a number of pieces in the puzzle and a
container of pieces. The "Solve" method uses a map to store the
association of edges to pieces. It iterates through the pieces and for
each edge, looks to see if its compliment is in the map. If so, it
rotates the new piece to the correct orientation and sets the adjacent
fields in the two edges to point at each other. If not, it adds the
edge to the map. With one pass through the pieces, it should have all
the pieces in the correct orientation and connected to all of the
adjacent pieces.

- WgpShashank May 25, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

what is jigsaw puzzle?

- Anonymous May 27, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A jigsaw puzzle:

Think of a big painting. Now cut the painting into 2 thousand small pieces. Now mix the pieces up and put them in a box. The puzzle is to reconstruct the pieces back into the picture.

- jiggyman November 24, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think a 2D array will suffice as a data structure.
Where each slot in the matrix knows and remembers who all are his neighbors.

- algooz June 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

hi ,

that is true... but how would you implement shuffle? Would you randomly generate the next block for every block?

- chinni September 16, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think a 2-d matrix would be too limiting.Wouldn't it assume that a non-boundary piece can have a constant number of neighbors.

- yahoo October 31, 2009 | 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