FastPrepLongest Increasing Path in a Matrix
Problems/Longest Increasing Path in a Matrix

Longest Increasing Path in a Matrix

Visa logoVisa● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies this task and its central operation. This practice version states the deterministic interface, boundary behavior, and ordering rules needed for consistent execution while preserving the reported capability.

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.

More Visa problems

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • House RobberPHONE SCREEN · Seen Nov 2026
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int longestIncreasingPath(int[][] matrix) {
        // write your code here
    }
}
Checking account…