Path Through an O/X Grid Using Only Right and Down
Problem statement
Given a rectangular array of strings grid, a zero-based coordinate source = [row, col], and a zero-based coordinate destination = [row, col], return whether the destination is reachable.
The character O is open and X is blocked. From an open cell you may move exactly one cell right or one cell down. A blocked endpoint is unreachable, and a destination above or left of the source is also unreachable.
Function
hasRightDownPath(grid: String[], source: int[], destination: int[]) → booleanExamples
Example 1
grid = ["OOO","OXO","OOO"]source = [0,0]destination = [2,2]return = trueMove right twice and then down twice while avoiding the center obstacle.
Example 2
grid = ["OX","XO"]source = [0,0]destination = [1,1]return = falseBoth first moves enter blocked cells.
Example 3
grid = ["OOO"]source = [0,2]destination = [0,0]return = falseReaching the destination would require moving left.
Constraints
1 <= grid.length, grid[i].length <= 500.- Every row has the same length, and the grid has at most
250000cells. - Every cell is
OorX. sourceanddestinationeach contain exactly two valid grid coordinates.