Reported August 2026
IMCdynamic programming

Grid Paths with Override Passes

Reported by candidates from IMC's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IMC OA. Under 2s to a working solution.
Founder's read

The edge case that breaks most first attempts at this IMC problem, reported in August 2026, is the start cell. It can be blocked, and so can the destination, and both of those cost a pass. The robot moves only Right or Down on an n x m grid, and you count paths that cross at most k blocked cells, modulo 10^9 + 7. The hinted pattern says BFS, but this is really a grid DP with a pass dimension. If you've got the OA coming up, learn the state shape now. StealthCoder is the safety net if you blank mid-assessment.

The problem

A delivery robot navigates a city represented by an n x m grid. A cell containing 1 is an open street, while a cell containing 0 is blocked by construction.
The robot starts at the top-left cell (0, 0) and must reach the bottom-right cell (n - 1, m - 1). The starting and ending cells may themselves be blocked. From any cell, the robot may move exactly one cell Right or one cell Down.
The robot has k override passes. Including one blocked cell in a path consumes exactly one pass, and the robot may consume at most k passes over its entire path.
Return the number of distinct paths from the start to the destination that use at most k override passes, modulo 10^9 + 7.

Function
numPaths(grid: int[][], k: int) → int

Examples
Example 1
grid = [[1,0,1],[1,0,1],[1,1,1]]
k = 1
return = 4
Four paths use at most one override pass. Three of them enter exactly one blocked cell, and the path that moves Down, Down, Right, Right enters no blocked cells.
Example 2
grid = [[1,0],[0,1]]
k = 0
return = 0
Both possible first moves enter a blocked cell, but no override pass is available.

Constraints
1 <= n, m <= 200
0 <= k <= 10
Every cell of grid is either 0 or 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Forget BFS. Moves only go Right and Down, so the grid is a DAG and you count paths with DP. Define dp[i][j][p] as the number of ways to reach cell (i, j) having used exactly p passes. Transition from the top and left neighbors, and add 1 to p when the cell you enter is 0. Sum dp[n-1][m-1][p] for p from 0 to k. The pitfall is the start cell. If grid[0][0] is 0, the base case is dp[0][0][1] = 1, not dp[0][0][0]. If k is 0 in that case, the answer is 0. Also guard p+1 against exceeding k, and apply the modulo on every addition. State count is 200 x 200 x 11, so it's fast. Roll the rows if you want less memory. If you freeze on the pass indexing during the live OA, StealthCoder can hand you the clean transition.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Grid Paths with Override Passes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass IMC's OA.

IMC reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Grid Paths with Override Passes FAQ

What's the actual trick in Grid Paths with Override Passes?+

Add the number of passes used as a third DP dimension. dp[i][j][p] counts paths reaching (i, j) with exactly p blocked cells entered. Each cell pulls from above and from the left. Entering a 0 cell shifts p up by one. Sum the last cell across all p up to k.

Why isn't BFS the right approach here?+

BFS finds shortest paths or reachability. This problem counts all distinct paths, and since moves are only Right and Down, there are no cycles. Counting on a DAG is a DP job. BFS would explode or double count without a per-state count, which is just DP anyway.

How do I handle a blocked start or end cell?+

The start cell counts as entered. If grid[0][0] is 0, initialize dp[0][0][1] = 1, and if k is 0 that means no valid path. If the end is 0, the transition into it costs a pass like any other blocked cell, so no special case is needed.

What's the complexity and will it pass the constraints?+

Time is O(n * m * k), roughly 200 * 200 * 11, about 440,000 states with two transitions each. That's trivial. Memory is fine as a full 3D array, or roll it to two rows. Just take the modulo 10^9 + 7 on every addition.

How do I prep for this in 48 hours?+

Write grid path counting with obstacles from scratch, then add the extra dimension for a budget like k. Test Example 2 by hand, where k = 0 gives 0. Then test a blocked start cell. Those two cases catch most off-by-one bugs in the pass counter.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IMC.

OA at IMC?
Invisible during screen share
Get it