Menu

3665. Twisted Mirror Path Count
πŸ“°

3665. Twisted Mirror Path Count

DEV Community: phpΒ·MD ARIFUL HAQUEΒ·18 days ago
#QCF8Afqd
#devto#dev#mirror#grid#cell
Reading 0:00
15s threshold

3665. Twisted Mirror Path Count

Difficulty: Medium

Topics: Staff , Array , Dynamic Programming , Matrix , Biweekly Contest 164

Given an m x n binary grid grid where:

grid[i][j] == 0 represents an empty cell, and

grid[i][j] == 1 represents a mirror.

A robot starts at the top-left corner of the grid (0, 0) and wants to reach the bottom-right corner (m - 1, n - 1) . It can move only right or down . If the robot attempts to move into a mirror cell, it is reflected before entering that cell:

If it tries to move right into a mirror, it is turned down and moved into the cell directly below the mirror.

If it tries to move down into a mirror, it is turned right and moved into the cell directly to the right of the mirror.

If this reflection would cause the robot to move outside the grid boundaries, the path is considered invalid and should not be counted.

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

Since the answer may be very large, return it modulo 10⁹ + 7 .

Note: If a…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.