Longest Path of Exact Jumps in a Grid
Updated
Problem statement
You are given a grid of m rows and n columns holding non-negative integers. You start in the top-left cell (0, 0).
From a cell holding the value v, one jump moves exactly v cells up, down, left or right. A jump must land inside the grid on a cell that has not been visited yet (the start cell counts as visited). A cell holding 0 allows no jump, so a path that reaches it ends there.
Return the largest number of jumps any such path can make.
Function
longestJumpPath(grid: int[][]) → intExamples
Example 1
grid = [[1,2,1],[0,1,1],[2,0,1]]return = 2One longest path: (0,0) → (0,1) → (2,1). From (0,0) the value 1 allows (0,1) or (1,0); (1,0) holds 0 and ends the path at once. From (0,1) the value 2 allows only (2,1), which holds 0. That is 2 jumps, and no path does better.
Example 2
grid = [[0,1],[1,1]]return = 0The start cell holds 0, so no jump is possible: the answer is 0.
Example 3
grid = [[1,1],[1,1]]return = 3Every cell holds 1, so each jump moves to a side neighbour. (0,0) → (0,1) → (1,1) → (1,0) visits all four cells: 3 jumps.
Constraints
1 <= m, n <= 5, wheremis the number of rows andnthe number of columns- every row of
gridhasncells 0 <= grid[r][c] <= 9
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEW
- Word SearchCognitiv · PHONE SCREEN
- Word SearchWhatNot · PHONE SCREEN
- Adjacent-Key Lock PatternsC3.ai · PHONE SCREEN
- Word Search IIApple · PHONE SCREEN
- Word SearchAmazon · ONSITE INTERVIEW
- Word SearchMicrosoft · ONSITE INTERVIEW
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEW
- Trace a Word Through a Letter GridExpedia · ONSITE INTERVIEW
- Rat in a Maze: All Simple PathsPeopleStrong · OA