Maximize the minimum value along a grid path
Company: Crowdstrike
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates a candidate's competence in graph traversal and path-optimization concepts, emphasizing reasoning about path scores and handling grid-based constraints.
Constraints
- 1 <= m, n <= 300
- -10^9 <= A[i][j] <= 10^9
- A is a rectangular matrix
Examples
Input: [[5,4,5],[1,2,6],[7,4,6]]
Expected Output: 4
Explanation: One optimal path is 5 -> 4 -> 5 -> 6 -> 6, whose minimum value is 4. No path can achieve a higher minimum.
Input: [[-5,-1],[-4,-7]]
Expected Output: -7
Explanation: Every valid path must end at -7, so the score cannot be greater than -7. Both possible paths have minimum value -7.
Input: [[8]]
Expected Output: 8
Explanation: The start and destination are the same cell, so the path score is simply 8.
Input: [[2,2,1,2,2,2],[1,2,2,2,1,2]]
Expected Output: 2
Explanation: There is a path from start to finish using only cells with value 2, so the minimum along that path is 2. Since the starting cell is 2, the answer cannot be larger than 2.
Input: [[7,5,3],[2,0,9],[4,5,9]]
Expected Output: 3
Explanation: The best route is 7 -> 5 -> 3 -> 9 -> 9, whose minimum is 3. Any other route is forced through a smaller bottleneck such as 2 or 0.
Hints
- If you guess a score X, can you check whether there is a path from start to end using only cells with value at least X?
- A priority queue can help you always extend the currently best bottleneck path first.