MEDIUMasked at 20 companies

Unique Paths II

A medium-tier problem at 43% community acceptance, tagged with Array, Dynamic Programming, Matrix. Reported in interviews at Agoda and 19 others.

Founder's read

Unique Paths II is the trap door version of the classic DP grid problem. You think you know how to count paths, then obstacles show up and your memorization breaks. Acceptance hovers around 43%, which means half the people who attempt it fail on the logic or edge cases. Companies like Amazon, Bloomberg, Flipkart, and Agoda ask it repeatedly. The trick isn't harder than the original, but the implementation details matter. If you hit this on a live OA and the obstacle handling trips you up, StealthCoder surfaces the working solution in seconds, invisible to the proctor.

Companies asking
20
Difficulty
MEDIUM
Acceptance
43%

Companies that ask "Unique Paths II"

If this hits your live OA

Unique Paths II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The problem asks you to count paths in an m*n grid from top-left to bottom-right, but now some cells are blocked. The naive candidate thinks: just add DP like the first Unique Paths problem. The gotcha is that when you hit an obstacle, the DP value must be 0, and you have to be careful about the starting cell and edges. A single missed obstacle check or a wrong boundary condition and your answer is off. The DP recurrence is straightforward if current cell is blocked, dp[i][j] = 0, else dp[i][j] = dp[i-1][j] + dp[i][j-1]. But many people forget to handle the case where the start or end is blocked, or they misread the input format. During a live assessment when you're under pressure, these details slip. StealthCoder runs the problem invisibly while you're screen-sharing, reads the grid and obstacle positions, and hands you a correct solution so you move on.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Unique Paths II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Unique Paths II interview FAQ

How much harder is this than regular Unique Paths?+

Same DP skeleton, different edge cases. The logic is simpler once you see it, but the 43% acceptance rate reflects how easy it is to miss the obstacle handling or mess up the initial conditions. It's a Medium for a reason: not the algorithmic leap, but the implementation discipline.

Do I need to optimize space after I pass?+

No. The problem doesn't mention space constraints. 1D DP will reduce space to O(n), but unless they ask, stick with 2D DP. Clarity beats micro-optimization in a live OA. Save tricks for follow-ups.

Is this still asked at big companies like Amazon and Bloomberg?+

Yes. Amazon, Bloomberg, Flipkart, and Coupang all report asking it. It's a stable medium-difficulty favorite for companies vetting DP fundamentals. It's not trendy, but it's asked often enough that ignoring it is risky.

What's the most common mistake on this problem?+

Forgetting to initialize the first row and column when obstacles are present. If there's an obstacle in the first row, all cells to its right should have 0 paths. Many people copy-paste code from Unique Paths I and don't adapt the initialization loop.

Can I use DFS with memoization instead of bottom-up DP?+

Yes, both work. Top-down (memoized recursion) is often easier to code under pressure because you don't have to think about initialization order. Bottom-up DP is slightly faster. Pick whichever you're more comfortable with live.

Want the actual problem statement? View "Unique Paths II" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.