Connect Two Game
In the "Link Link" game, you can eliminate two identical tiles by connecting them, but only if the connecting line has no more than two turns. If the line exceeds two turns, the tiles cannot be eliminated.
In this problem, you are asked to implement the connect
function. Given the game board board
and the coordinates of two tiles clicked by the user row1, col1, row2, col2
, determine whether these two tiles can be connected. If they can be connected within two turns, return the connection path; otherwise, return an empty result. Please see the details below:
Link Link Game
The general solution for this problem is the BFS algorithm, but compared with typical algorithm problems on LeetCode, the scenarios in the Link Link game are more complex:
There is a restriction of "no more than two turns".
You need to record the exact connection path between the two tiles.
In the Link Link game, the connecting line may go outside the boundaries of the board for tiles on the edge.
Try to solve it yourself first. Below, I will provide a reference solution.