Longest Strictly Rising Drone Survey Path Across a Terrain Grid
Last updated: November 29, 2026
Quick Overview
Given a grid of terrain elevations, return the length of the longest path that moves in four directions and strictly increases in elevation at every step.
Amazon
November 29, 20260
0
0 solved
Given a grid of terrain elevations, return the length of the longest path that moves in four directions and strictly increases in elevation at every step.
Prime Air survey planning sometimes needs monotone climbs for sensor calibration. Interviewers check that you notice strict increase makes the move graph acyclic, then use DFS with memoization (or topological peeling) instead of exponential search.
What the Interviewer Expects
- Recognize that strict increase means no cycles, so the graph is a DAG
- Memoize the longest path starting at each cell
- Avoid a visited set since cycles are impossible
- Discuss recursion depth and an iterative topological alternative
- State O(m * n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the path itself, not just its length?
- What if equal heights are allowed (non-decreasing)?
- How would you do it iteratively to avoid deep recursion on a 1000 x 1000 grid?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: an m x n matrix of integers. Moves go to the four neighbors only, no wrap-around, and the next cell must be strictly higher. Output the maximum number of cells on such a path (at least 1 for a ...
High-Level Design
Define best(r, c) as the longest rising path that starts at (r, c). It equals 1 plus the maximum best over strictly higher neighbors. Because every edge goes to a strictly higher value, no path ca...