Tap here to switch tabs
Problem
Submissions

Problem: Twisted Mirror Path Count

med
30 min
Try to solve the Twisted Mirror Path Count problem.

Statement

Given an m $ imes$ n 2D binary matrix grid, a robot begins at the top left cell (0, 0) and wants to reach the bottom right cell (m - 1, n - 1).

From any cell with a value of 00, the robot can choose to move in one of two directions:

  • Move right

  • Move down

Cells with a value of 11 act as mirrors and cannot be stopped on:

  • Entering a mirror while moving right deflects the robot downward.

  • Entering a mirror while moving down deflects the robot rightward.

  • If the deflected destination is another mirror, the robot continues to deflect according to its current direction of movement until it lands on an empty cell containing 00 or moves outside the grid boundaries.

Any path that moves outside the boundaries of the grid is invalid.

Return the total number of unique paths from (0, 0) to (m - 1, n - 1).

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 2≤2 \leq m, n ≤500\leq 500

  • grid[i][j] is either 00 or 11.

  • grid[0][0] == grid[m - 1][n - 1] == 0

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Twisted Mirror Path Count

med
30 min
Try to solve the Twisted Mirror Path Count problem.

Statement

Given an m $ imes$ n 2D binary matrix grid, a robot begins at the top left cell (0, 0) and wants to reach the bottom right cell (m - 1, n - 1).

From any cell with a value of 00, the robot can choose to move in one of two directions:

  • Move right

  • Move down

Cells with a value of 11 act as mirrors and cannot be stopped on:

  • Entering a mirror while moving right deflects the robot downward.

  • Entering a mirror while moving down deflects the robot rightward.

  • If the deflected destination is another mirror, the robot continues to deflect according to its current direction of movement until it lands on an empty cell containing 00 or moves outside the grid boundaries.

Any path that moves outside the boundaries of the grid is invalid.

Return the total number of unique paths from (0, 0) to (m - 1, n - 1).

Constraints:

  • m == grid.length

  • n == grid[i].length

  • 2≤2 \leq m, n ≤500\leq 500

  • grid[i][j] is either 00 or 11.

  • grid[0][0] == grid[m - 1][n - 1] == 0