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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

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
DFS
memoization
DAG longest path
matrix
topological sort
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported