Shortest Increasing Path to a Target
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure that carries this one is a queue. Uber reported this OA in September 2026, and it's a shortest path on a grid dressed up with two twists: you can only step to strictly larger values, and ties break by lexicographically smallest encoded path. It's BFS on an implicit graph, and the ordering rule is where people slip. If the invite is in your inbox, read the tie-break rule twice before you write anything. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below is enough to get you moving.
The problem
Start at the top-left cell of grid. You may move up, down, left, or right only to a cell whose value is strictly greater than the current cell's value. Return a shortest path ending at any cell whose value equals target. Encode a cell as row * columnCount + column. If multiple shortest paths exist, return the lexicographically smallest encoded path. Return an empty array if the target is unreachable. Function shortestIncreasingPath(grid: int[][], target: int) → int[] Examples Example 1 grid = [[1,2,9],[4,5,3],[7,6,8]] target = 5 return = [0,1,4] Paths [0,1,4] and [0,3,4] both use two moves. The first is lexicographically smaller. Example 2 grid = [[5,4],[3,6]] target = 6 return = [] Neither neighbor of the starting value 5 is greater, so no move is possible. Constraints 1 <= grid.length, grid[i].length <= 300. Every row has the same length. Every value and target fits a signed 32-bit integer.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Strictly increasing moves mean the graph is a DAG, so no cell repeats on a path and you don't need a visited set for correctness. BFS from cell 0 gives shortest distance in moves. The trap is the lexicographic tie-break. Don't store whole paths in the queue, that blows memory on a 300 by 300 grid. Instead, compute distances with BFS, then find the target cells at minimum distance. Rebuild the path by walking forward from the start, at each step picking the smallest encoded neighbor that is on a shortest route to a target. That needs a backward reachability pass from the best targets. Another option is processing neighbors in sorted order and keeping the first parent, but check it carefully against the encoded-path ordering across levels. Edge cases: start cell already equals target returns [0], and no valid move returns []. StealthCoder is your hedge if the reconstruction logic falls apart live.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Shortest Increasing Path to a Target 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Shortest Increasing Path to a Target FAQ
What's the core trick in the Uber shortest increasing path problem?+
Treat the grid as an implicit graph and run BFS for fewest moves. The increasing-value rule makes it acyclic, so each cell is only reached along valid paths. The real work is the lexicographic tie-break, which needs a deliberate reconstruction step instead of storing paths.
How do I handle the lexicographically smallest path?+
Run BFS to get distances, mark cells that lie on some shortest path to a minimum-distance target by going backward, then walk forward from the start choosing the smallest encoded neighbor among marked cells. This avoids carrying full paths in the queue.
Can I use Dijkstra or DFS instead?+
Dijkstra works but is overkill since every move costs 1. DFS with memoization can work because the graph is acyclic, but BFS is simpler and cleaner for shortest distance. Pick BFS and spend your effort on the tie-break.
What edge cases should I test?+
Test the start cell equal to target, which returns [0]. Test a start with no larger neighbor, which returns []. Test a target value that never appears. Test a 1 by 1 grid. Test multiple target cells at the same distance, where the smaller encoded path must win.
How should I prepare in 48 hours for this?+
Write grid BFS from memory a few times, including the direction array and bounds checks. Then practice one problem that needs path reconstruction with a tie-break. Watch complexity: 90,000 cells is fine for O(n*m) but not for storing a path per cell.