Ctrl K

Pipe Tiles

Medium
A board 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.
Example 1
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.

Example 2
tiles=[[2], [2], [2]] → True

Three vertical pipes stacked on top of each other: water flows straight down.

Example 3
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.

Constraints
  • 1 ≤ m, n ≤ 300
  • 1 ≤ tiles[i][j] ≤ 6
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDrain the Landlocked Ponds MediumLand Regions on a Map MediumLargest Forest Patch MediumA Board Cut by Slashes MediumLandlocked Land Cells Medium
loading Python…
Input
tiles=[[4, 3], [6, 5]]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.