Find A Threshold-Limited Path With Minimum Required Safety
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: Practice a graph path interview problem that asks for the minimum required safety value along a threshold-limited path. The prompt targets minimax path reasoning, filtered edges, Dijkstra-style relaxation, disconnected graphs, and edge-case handling.
Constraints
- The graph is undirected.
- Only edges with cost <= threshold are usable.
Examples
Input: (4, [(0,1,5),(1,3,4),(0,2,2),(2,3,8)], 0, 3, 6)
Expected Output: 5
Input: (3, [(0,1,7),(1,2,3)], 0, 2, 5)
Expected Output: -1
Input: (1, [], 0, 0, 10)
Expected Output: 0
Input: (3, [(0,1,1),(1,2,2),(0,2,10)], 0, 2, 10)
Expected Output: 2
Input: (3, [(0,1,1),(1,2,2),(0,2,10)], 0, 2, 1)
Expected Output: -1
Input: (5, [(0,1,4),(1,4,4),(0,2,3),(2,3,9),(3,4,3)], 0, 4, 9)
Expected Output: 4
Input: (5, [(0,1,4),(1,4,4),(0,2,3),(2,3,9),(3,4,3)], 0, 4, 3)
Expected Output: -1
Input: (2, [(0,1,0)], 0, 1, 0)
Expected Output: 0
Hints
- The path cost is the maximum edge cost, not the sum.
- Dijkstra works with max(current, edge_cost) as the relaxation value.