My friend was asked this question on Amazon SDE 2 virtual onsite interview.
Location: Seattle
Team: Alexa
YOE: 5
Imagine you are developing a robot that,
when given a jigsaw puzzle in a box,
solves the puzzle and returns the box
with the solved puzzle inside.
Firstly, create data structures that will
represent the PuzzleBox.
Next, implement the solve() method using
the data structures you just created. This
method will receive the PuzzleBox with a
jumbled puzzle inside, and will return the
same PuzzleBox object with a solved
representation of the puzzle. Here is the
method signature:
PuzzleBox solve(PuzzleBox puzzle) {
// returns the solved representation of
// the puzzle
}
Notes:
- You are given an existing helper function
that is already written for you. It is
called fitsWith. It takes two parameters,
edgeA and edgeB and returns true if the
edges fit together.
- In the context of this question, "Edge"
means one of the 4 sides of a single puzzle
piece. - Note: it already contasins
- Some types of Edges are not supposed to connect
to other Edges at all.
- If an Edge is the type that is
supposed to connect
to another Edge, then it will only fit with one
specific Edge. In other words, if two pieces
fit together, then it is correct to connect them.
- The puzzle pieces are in a random order, but
they will never rotate. There is a known "top"
side of each piece.
- All pieces are square and conform to an NxM
grid shape
- The goal of this question is to see how
well you organize your code. Focus on writing
clean, readable code. Don't spend too
much time trying to find the most efficient
algorithm.
*/