We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Since, a lot of coders are struggling to visualize the problem, here's an attempt to simplify it. Most of the queries are about valid/invalid testcases. I think the root cause of confusion is that the problem is being understood in "hexagonal frame" while implemented in "rectangular frame".
Let's transform it for better understanding. The 2xN hexagonal grid and 2x1 valid dominoes given in problem statement are as follows:
Direct transformation from hexagon to rectangle gives the following structure :
Now, the upper row can be shifted slightly towards right to give regular rectangular grid :
Notice the corresponding changes in the valid dominoes ! This not only explains validity of testcases but also simplifies the implementation to great extent.
Query : Why is 10 01 accepted but not 01 10 ?
Here's the grid representation of above input :
a) 10 b) 01
01 10
As it can be seen, the first input requires domino with "forward slash /" structure, which is a valid domino (2nd in above pic). Hence, it can be filled. On the other hand, second input requires domino with "backward slash \" structure, which doesn't exist.
Hexagonal Grid
You are viewing a single comment's thread. Return to all comments →
Since, a lot of coders are struggling to visualize the problem, here's an attempt to simplify it. Most of the queries are about valid/invalid testcases. I think the root cause of confusion is that the problem is being understood in "hexagonal frame" while implemented in "rectangular frame".
Let's transform it for better understanding. The 2xN hexagonal grid and 2x1 valid dominoes given in problem statement are as follows:
Direct transformation from hexagon to rectangle gives the following structure :
Now, the upper row can be shifted slightly towards right to give regular rectangular grid :
Notice the corresponding changes in the valid dominoes ! This not only explains validity of testcases but also simplifies the implementation to great extent.
Query : Why is
10 01
accepted but not01 10
?Here's the grid representation of above input :
As it can be seen, the first input requires domino with "forward slash
/
" structure, which is a valid domino (2nd in above pic). Hence, it can be filled. On the other hand, second input requires domino with "backward slash\
" structure, which doesn't exist.