#3665

Twisted Mirror Path Count

specialist · 910 · lc medium +31 · 48.1% accepted · 83 likes · top 34%

Description

An m x n binary grid has empty cells (0) and mirrors (1). A robot at (0, 0) navigates to (m-1, n-1) moving only right or down. When the robot's intended move leads into a mirror, it is deflected: a rightward move becomes downward (entering the cell below the mirror), and a downward move becomes rightward (entering the cell to the right). Consecutive mirrors trigger repeated reflections. Paths that go out of bounds are invalid. Return the count of unique valid paths modulo 109 + 7.

Code

1
2
3