Reported September 2026
Visadepth first search

Longest Increasing Path in a Matrix

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

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

Four directions, no diagonals, no wrap-around, and a cell can show up only once in a path. That's the fine print in the Visa longest increasing path question reported in September 2026, and it's what makes the problem cleaner than it looks. Strictly increasing means you can never loop back, so the grid is secretly a DAG. The matrix goes up to 200 by 200, which rules out brute force. If you blank when the OA timer starts, StealthCoder runs invisibly as a safety net and hands you the structure. Know the trick first, though. It's short.

The problem

Given an integer matrix, return the maximum number of cells in a strictly increasing path.
From a cell you may move up, down, left, or right. Diagonal moves and wrap-around moves are not allowed. A cell may appear at most once in a path.

Function
longestIncreasingPath(matrix: int[][]) → int

Examples
Example 1
matrix = [[9,9,4],[6,6,8],[2,1,1]]
return = 4
One longest path is 1 to 2 to 6 to 9.
Example 2
matrix = [[3,4,5],[3,2,6],[2,2,1]]
return = 4
The path 3,4,5,6 has length four.
Example 3
matrix = [[]]
return = 0
A matrix with no cells has no path.

Constraints
0 <= rows, columns <= 200.
Every row has the same length.
Cell values fit in a signed 32-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is DFS with memoization. For each cell, compute the longest increasing path starting there. Look at the four neighbors with strictly larger values, take the best of their results, and add one. Cache the answer per cell so each cell is solved once. Total work is O(rows * cols). Because values must strictly increase, you don't need a visited set, and that's the pitfall: people add one and break the memo. The other pitfall is the empty matrix. Example 3 is [[]], so check for zero rows or zero columns and return 0 before touching matrix[0]. Recursion depth can reach 40000 in a snake-like grid, so watch your language's stack limit. The alternative is topological sort by peeling off cells with no smaller neighbor, layer by layer, which is where the BFS hint comes from. If the recursion limit or the memo logic slips mid-assessment, StealthCoder is the hedge that shows a working version on screen.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Longest Increasing Path in a Matrix 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as longest increasing path in a matrix. If you have time before the OA, drill that.

⏵ The honest play

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

Visa reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Increasing Path in a Matrix FAQ

What's the trick for the Visa longest increasing path problem?+

Memoized DFS. Store the longest path starting at each cell. Since moves need strictly larger values, there are no cycles, so you skip a visited set. Each cell is computed once, giving O(rows * cols) time and space.

Should I use DFS or BFS here?+

Either works. DFS with memoization is the shortest to write. BFS means a topological sort: count each cell's smaller neighbors, peel off the zeros layer by layer, and the number of layers is the answer. It avoids recursion depth issues.

What edge cases does this problem hide?+

The empty matrix, shown as [[]] with an answer of 0. Also equal neighbors, which can't be used because the path must be strictly increasing. Example 1 has repeated 9s and 6s that trip up people who use greater-or-equal.

How hard is it really for an OA?+

Medium-hard on paper, but it's a known pattern. If you've seen memoized grid DFS, it's about 20 lines. The difficulty is recognizing that no visited set is needed and that the cache makes it linear.

How do I prepare in 48 hours?+

Write this one from scratch twice, once with recursive DFS and memo, once with the topological sort. Test it on the three given examples, especially [[]]. Then check your language's recursion limit, since a 200 by 200 grid can go deep.

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

OA at Visa?
Invisible during screen share
Get it