Reported September 2026
New Relicdepth first search

Longest Increasing Path in a Matrix

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

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

The New Relic OA reported in September 2026 asks for the longest strictly increasing path in a matrix, and the trap is the empty input. A matrix like [[]] has zero columns, so row 0 exists but has no cells, and a solution that reads matrix[0][0] or matrix[0].length blindly will crash. The real pattern is DFS with memoization, which a hinted BFS approach can also match via topological ordering. If you blank mid-assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the structure. Know the trick first and you won't need it.

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

Run a DFS from every cell and cache the longest path starting at that cell. Because moves only go to strictly larger values, the graph is a DAG, so no visited set is needed and cycles can't happen. Each cell is solved once, giving O(rows * cols) time. The common pitfall is skipping the memo, which makes it exponential and times out near 200 by 200. The other pitfall is the edge case: guard against an empty matrix or empty first row before you touch any index, and return 0. Also remember equal neighbors do not count, so use a strict comparison. The BFS alternative is Kahn's algorithm on in-degrees, counting layers. If you freeze on the live OA, StealthCoder is the hedge that reads the prompt and gives you a working memoized DFS fast.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

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 would have shipped this the night before his JPMorgan OA if he'd had it.

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 New Relic's OA.

New Relic reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Increasing Path in a Matrix FAQ

What's the trick in the New Relic longest increasing path problem?+

DFS with memoization. Store the best path length starting from each cell. Since you only move to strictly larger values, there are no cycles, so you don't need a visited set. Each cell gets computed once, which keeps it at O(rows * cols).

What edge case breaks a naive solution?+

The empty matrix. Example 3 is [[]], which has zero cells and should return 0. If you read matrix[0][0] or compute columns before checking, you'll crash. Check for zero rows or zero columns first and return 0 immediately.

Can I solve it with BFS instead of DFS?+

Yes. Treat each cell as a node with edges to larger neighbors, compute in-degrees, and run a topological sort layer by layer. The number of layers is the answer. It's the same complexity as memoized DFS, and it avoids recursion depth worries.

Will plain DFS without memo pass at 200 by 200?+

No. Without caching, paths get re-explored over and over and runtime blows up exponentially on increasing grids. With 40,000 cells possible, you need memoization or the topological approach to stay linear in the number of cells.

How do I prepare for this in 48 hours?+

Write the memoized DFS from scratch twice. Then test it on the three examples, especially [[]]. Practice the four-direction bounds check and the strict greater-than comparison. That covers nearly every mistake people make on this one.

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

OA at New Relic?
Invisible during screen share
Get it