Longest Consecutive Decreasing Grid Path
Updated
Problem statement
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[][]) → intExamples
Example 1
grid = [[5,4,3],[6,1,2],[7,0,-1]]return = 9The path follows 7,6,5,4,3,2,1,0,-1.
Example 2
grid = [[3,2],[2,1]]return = 3Either cell containing 2 can connect 3 to 1.
Example 3
grid = [[4,1],[2,0]]return = 2The 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