FastPrepLongest Consecutive Decreasing Grid Path
Problems/Longest Consecutive Decreasing Grid Path

Longest Consecutive Decreasing Grid Path

Google logoGoogle● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand new-grad report from Google asks for the longest path in a grid with values that decrease by one at each step. Comments confirm a DFS-style approach with four neighbors. We made the decrease-by-one rule from the reported examples explicit. Our version is about 92% the same as the reported question.

Given a nonempty integer matrix grid, return the maximum number of cells in a path whose values decrease consecutively.

From a cell with value x, the next cell must share an edge with it and have value exactly x - 1. A path may start at any cell and move up, down, left, or right.

Function

longestConsecutiveDecreasingPath(grid: int[][]) → int

Examples

Example 1

grid = [[5,4,3],[6,1,2],[7,0,-1]]return = 9
grid
01205431612270-1

The path follows 7,6,5,4,3,2,1,0,-1.

Example 2

grid = [[3,2],[2,1]]return = 3
grid
01032121

Either cell containing 2 can connect 3 to 1.

Example 3

grid = [[4,1],[2,0]]return = 2
grid
01041120

The longest path is 1,0; diagonal cells are not adjacent.

Constraints

  • 1 <= grid.length, grid[0].length <= 200.
  • Every row has the same length.
  • Every value is a signed 32-bit integer.

More Google Phone Screen questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Count Starts Reaching a Grid MaximumDuolingo · PHONE SCREENDuolingo interview questions
  • Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
  • Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
  • Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
  • Longest Increasing Path in a MatrixNutanix · OANutanix interview questions
  • Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • House Robber IIIOkta · PHONE SCREENOkta interview questions
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • House Robber IIIGoldman Sachs · PHONE SCREENGoldman Sachs interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int longestConsecutiveDecreasingPath(int[][] grid) {
        // Write your code here.
    }
}
Checking account…