field with m rows and n columns of non-negative integers, and an integer divisor. You start in the top-left cell (0, 0) and walk to the bottom-right cell (m − 1, n − 1), moving only down or right.
The sum of a path is the sum of the numbers in every cell it visits, including the first and the last.
Return how many paths have a sum divisible by divisor. The answer can be large, so return it modulo 10⁹ + 7.field=[[1, 2], [3, 4]], divisor=4 → 1
There are two paths: 1 → 2 → 4 with sum 7 and 1 → 3 → 4 with sum 8. Only the second is divisible by 4.
field=[[2, 4, 6]], divisor=3 → 1
The only path runs right along the row, and its sum 12 is divisible by 3.
field=[[0, 5, 1], [3, 2, 9]], divisor=7 → 1
field=[[1, 2], [3, 4]], divisor=4
1
Run checks the first 3 tests in your browser. Submit checks all 73 tests on the server, hidden ones included.