Jigsaw puzzle in which each piece has 3 tab and 1 blank. How to check if given number of rows and columns, the puzzle is solvable or not?

186 Views Asked by At

You are given a special jigsaw puzzle consisting of n⋅m identical pieces. Every piece has three tabs and one blank, as pictured below.

The jigsaw puzzle is considered solved if the following conditions hold: 1. The pieces are arranged into a grid with n rows and m columns. 2. For any two pieces that share an edge in the grid, a tab of one piece fits perfectly into a blank of the other piece.

We can have blank or tab at the perimeter.image of single piece

I couldn't figure out what to do even after looking into lots of articles. This was asked as a programming problem and I seem to have stuck.