As reported: D. E. Shaw online assessment for 2027 graduates (2026): a data package is an
n × mmatrix of encryption codes 0 or 1; a 0 is a security breach, and any unit within a certain latency threshold (Manhattan distance) of a breach unit is also a breach; count the paths from(0, 0)to(n − 1, m − 1)moving only right or down that avoid every breach unit, modulo10^9 + 7.
You are given an n × m matrix packages of 0s and 1s and a latency threshold k.
- Every unit holding
0is a breach. - Every unit whose Manhattan distance
|p − r| + |q − s|to some0unit is at mostkis also a breach.
Count the paths from (0, 0) to (n − 1, m − 1) that move only right or down and never enter a breach unit (including the start and the end). Return the count modulo 10^9 + 7.
Example 1
packages = [[1,1,1,1],
[1,1,1,1],
[0,1,1,1],
[1,1,1,1]]
k = 1
Output: 7
The breach units are (2,0) and its neighbours (1,0), (3,0), (2,1).
Example 2
packages = [[1,1,1],[1,1,1],[1,1,1]], k = 2
Output: 6
No breaches: all C(4, 2) = 6 paths.
Constraints: 1 ≤ n, m ≤ 500; packages[i][j] ∈ {0, 1}; 0 ≤ k ≤ 1000.
Code runner format: one JSON value per line: packages, then k. Implement countSafePaths(packages, k).