You are given a 2D grid of size m x n, where each cell either contains:
0 → an open space
1 → a mirror tile
A robot starts at position (0, 0) and must reach (m-1, n-1). It may only move right or down.
However, when the robot tries to move into a mirror cell, it does not enter the mirror directly. Instead, it gets redirected:
If it was moving right, it is redirected down.
If it was moving down, it is redirected right.
This redirection continues if the robot is redirected into another mirror cell, meaning mirror reflections can chain repeatedly.
If at any point the redirection would move the robot outside the grid, then that path is considered invalid.
Your task is to compute how many distinct valid paths lead from the start to the goal cell.
Return the result modulo 10⁹ + 7.
Input: grid = [[0,0,1], [1,0,0], [0,1,0]]
Output: 1
Explanation:
There are 1 valid reflected paths that successfully reach the bottom-right cell.
Input: grid = [[1,1],[1,1]]
Output: 0
Explanation:
Every move leads to reflection loops or out-of-bounds.
Input: grid = [[1,0],[0,0]]
Output: 0
Explanation:
Only one possible path avoids going out of bounds after reflections.
Accepted:
Submission: