Getting Ready: Jigsaw Puzzle

Understand the jigsaw puzzle problem and learn the questions to simplify this problem.

Problem definition

A jigsaw puzzle is a picture divided into irregularly shaped pieces that can be assembled together to form a complete picture. A puzzle has a fixed number of pieces that can only fit together in exactly one way. We can solve the jigsaw puzzle by aligning the pieces in a way that they fit with each other and also create a coherent picture.

Expectations from the interviewee

Although the jigsaw problem is a simpler design problem asked in interviews, the interviewer still has some expectations. The following provides an overview of what the interviewer wants to hear you discuss in more detail during the interview.

The puzzle board

You may want to ask the interviewer more about the kind of jigsaw puzzle. You can ask the following questions:

  • What does a jigsaw puzzle look like. Is there a picture or a pattern on the puzzle?

  • What type of shape does our board have? Is it rectangular, circular, or any other shape?

The puzzle pieces

It is important to clarify the requirements for a single piece of the puzzle as it is a key feature of the problem. You can ask the following questions:

  • What kind of shape do the puzzle pieces have? How many sides does a piece have?

  • How do the pieces fit together?

  • Will all the pieces of a jigsaw puzzle be unique?

Design approach

We are going to design this jigsaw puzzle using the bottom-up design approach. For this, we will follow the steps below:

  • Identify and design the smallest components first like the puzzle edges of a piece.

  • Use these small components to design bigger components, for example, the puzzle piece.

  • Repeat the steps above until we design the whole system, i.e., the puzzle board.

Design pattern 

During an interview, it is always a good practice to discuss the design patterns that a Jigsaw puzzle falls under. Stating the design patterns gives the interviewer a positive impression and shows that the interviewee is well-versed in the advanced concepts of object-oriented design.

Try to answer the following question. If you are not familiar with design patterns, don’t worry! You can learn about them by asking questions like, “Define design patterns.”

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy