Find best downhill ski run from a start
Company: Airbnb
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
Quick Answer: This question evaluates algorithmic problem-solving in grid graph traversal and dynamic programming, requiring computation of the maximum-length strictly decreasing path from a start cell plus analysis of time and space complexity.
Part 1: Maximum Downhill Score for One Skier
Constraints
- 0 <= R, C
- If the grid is non-empty, all rows have the same length
- If the grid is non-empty, 1 <= R * C <= 100000
- -10^9 <= grid[r][c] <= 10^9
- If the grid is non-empty, the given start cell is within bounds
Examples
Input: ([[9, 6, 3], [8, 7, 2], [5, 4, 1]], 0, 0)
Expected Output: 7
Explanation: One optimal run is 9 -> 8 -> 7 -> 6 -> 3 -> 2 -> 1, which visits 7 cells.
Input: ([[5, 5], [5, 5]], 0, 0)
Expected Output: 1
Explanation: No move is allowed because all neighboring cells have equal elevation, not lower.
Input: ([[42]], 0, 0)
Expected Output: 1
Explanation: A single-cell grid always has score 1 because the start cell counts.
Input: ([], 0, 0)