PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Find A Threshold-Limited Path With Minimum Required Safety

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an undirected graph with `n` nodes, a list of weighted edges, a start node, an end node, and a safety threshold. Each edge has a safety cost. Return the minimum possible value of the maximum edge cost used on any valid path from start to end, where every edge on the path must have cost less than or equal to the threshold. If no valid path exists, return `-1`. Function signature: ```python def minimum_required_safety(n: int, edges: list[tuple[int, int, int]], start: int, end: int, threshold: int) -> int: pass ``` Constraints: - `0 <= start, end < n`. - Edge costs may repeat. - The graph may be disconnected. - A path may contain one or more edges; if `start == end`, return `0`. - Only edges with cost less than or equal to `threshold` may be used. Examples: ```text n = 4, edges = [(0, 1, 5), (1, 3, 4), (0, 2, 2), (2, 3, 8)], start = 0, end = 3, threshold = 6 Output: 5 Explanation: 0 -> 1 -> 3 is valid and its maximum edge cost is 5. ``` ```text n = 3, edges = [(0, 1, 7), (1, 2, 3)], start = 0, end = 2, threshold = 5 Output: -1 ```

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.

Use only edges whose cost is at most threshold. Among valid paths from start to end, minimize the maximum edge cost on the path.

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

  1. The path cost is the maximum edge cost, not the sum.
  2. Dijkstra works with max(current, edge_cost) as the relaxation value.
Last updated: Jul 8, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Build Prefix Lookup with a Trie - Google (medium)
  • Deterministic Task Execution Order - Google (easy)
  • Busiest Rental Car - Google (easy)
  • Find Common Free Time Slots Across Calendars - Google (easy)
  • Count Clusters of 2D Points Within a Radius - Google (medium)