Unique Paths III
A hard-tier problem at 82% community acceptance, tagged with Array, Backtracking, Bit Manipulation. Reported in interviews at Cruise and 1 others.
Unique Paths III shows up in Cruise and Pinterest OAs, and most candidates blank on it because the obvious grid-walk intuition fails. You've got a matrix with obstacles, a start square, an end square, and exactly one rule: you must visit every non-obstacle cell exactly once before reaching the end. The acceptance rate sits at 82%, but that number hides the trick. Backtracking alone isn't enough; you need bit manipulation to track which cells you've visited without blowing up your recursion stack. If this problem hits your live OA and you can't remember how to encode the visited state, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Unique Paths III"
Unique Paths III 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trap is thinking you can treat this like a standard shortest-path problem. You can't. You have to visit all non-obstacle cells exactly once, which means you're doing an exhaustive search over valid Hamiltonian paths. Backtracking is the right move, but you need a way to track visited cells that doesn't require a fresh 2D array on every recursive call. Bit manipulation is the answer: encode each cell's visited state as a single bit in an integer bitmask. For each cell, convert its row and column to a bit index, flip that bit when you visit, and flip it back on backtrack. This keeps your state compact and fast. Common mistake: using a separate visited set and forgetting to restore it properly, tangling your backtracking logic. Another trap: not counting the start and end cells correctly when checking if you've hit all non-obstacles. StealthCoder handles the bitmask encoding and the exhaustive recursion so you're not doing mental math under pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Unique Paths III recycles across companies for a reason. It's hard-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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Unique Paths III interview FAQ
Is this really hard, or does it just look hard?+
It's genuinely hard. The 82% acceptance rate is misleading because most who solve it have seen backtracking with bitmasks before. If you haven't drilled state encoding, you'll lose 10 to 20 minutes on the implementation. The algorithmic idea is simple; the execution is the killer.
Why can't I just use a 2D visited array and backtrack normally?+
You can, but it's slower and error-prone. Copying or resetting a 2D array on every recursive call adds overhead. A bitmask is a single integer you flip one bit at a time. It's faster and makes your backtracking logic cleaner because you're working with a single value, not managing array state across recursive calls.
Do Cruise and Pinterest ask variations of this, or just the exact problem?+
Unknown from reports. But both companies test backtracking and state-space search. If they ask this, they're checking whether you can encode state efficiently and think in terms of exhaustive enumeration. Expect follow-ups on optimization or variants.
How do I convert a matrix cell to a bit index?+
If your matrix is m rows and n columns, convert (row, col) to a single index: row * n + col. That becomes your bit position in the bitmask. Use (1 << index) to create the bit, and XOR it with your mask to toggle visited status.
What's the time complexity, and does it matter?+
Worst case is O(4^(m*n)) because you're exploring all possible paths. In practice, it's much faster because obstacles and the single-visit constraint prune the search space. You won't optimize this further; the interviewer wants to see you code it correctly and understand why backtracking is the right tool.
Want the actual problem statement? View "Unique Paths III" on LeetCode →