tiles of size m × n is covered with pipe pieces. The number in each cell says which two sides of the tile its pipe joins:
| Tile | Joins |
|---|---|
| 1 | left and right |
| 2 | top and bottom |
| 3 | left and bottom |
| 4 | right and bottom |
| 5 | left and top |
| 6 | right and top |
Water can move into a neighbouring cell only when both tiles open towards each other. Tiles cannot be rotated.
Return true if water starting in the top-left cell can reach the bottom-right cell, and false otherwise.tiles=[[4, 3], [6, 5]] → True
Tile 4 opens to the right, tile 3 next to it opens left and down, and tile 5 below it opens up, so water reaches the bottom-right corner.
tiles=[[2], [2], [2]] → True
Three vertical pipes stacked on top of each other: water flows straight down.
tiles=[[1, 1, 2]] → False
Water passes through two horizontal pipes, but the vertical tile 2 at the end has no opening on its left, so it stops there.
tiles=[[4, 3], [6, 5]]
True
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.