PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

This question evaluates proficiency in graph algorithms and shortest-path computation, specifically handling weighted directed graphs, non-negative travel times, and reachability.

  • medium
  • Waymo
  • Coding & Algorithms
  • Software Engineer

Compute ETA between two map nodes

Company: Waymo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given a **semantic road map** represented as a weighted graph. Each node is an intersection/waypoint, and each edge represents a drivable road segment with an associated **travel time** (in seconds). Given two nodes `start` and `end`, compute the **ETA** (minimum travel time) from `start` to `end`. ## Clarifications to confirm with interviewer - Is the graph **directed** (one-way roads) or **undirected**? (Assume directed unless stated otherwise.) - Are travel times **non-negative**? (Assume yes.) - What should be returned if `end` is unreachable from `start`? (Return `-1`.) - Are there **multiple queries** or a single query? (Assume a single query unless specified.) ## Input / Output (one possible interface) - Input: - `n`: number of nodes labeled `0..n-1` - `edges`: list of roads, each as `(u, v, t)` meaning an edge from `u` to `v` taking `t` seconds - `start`, `end`: node IDs - Output: - Minimum travel time from `start` to `end`, or `-1` if unreachable ## Constraints - `1 <= n <= 2e5` - `0 <= |edges| <= 5e5` - `0 <= t <= 1e9` (non-negative) ## Example - `n = 5` - `edges = [(0,1,5),(1,2,2),(0,2,20),(2,3,1),(3,4,3)]` - `start = 0, end = 4` Shortest ETA path is `0->1->2->3->4` with total time `5+2+1+3 = 11`, so return `11`.

Quick Answer: This question evaluates proficiency in graph algorithms and shortest-path computation, specifically handling weighted directed graphs, non-negative travel times, and reachability.

You are given a semantic road map represented as a directed weighted graph. Each node is an intersection or waypoint labeled from 0 to n-1, and each edge (u, v, t) represents a drivable road from node u to node v that takes t seconds to travel. Compute the minimum travel time (ETA) from start to end. If end cannot be reached from start, return -1. All travel times are non-negative.

Constraints

  • 1 <= n <= 200000
  • 0 <= len(edges) <= 500000
  • 0 <= u, v < n
  • 0 <= t <= 1000000000
  • Travel times are non-negative

Examples

Input: (5, [(0,1,5),(1,2,2),(0,2,20),(2,3,1),(3,4,3)], 0, 4)

Expected Output: 11

Explanation: The fastest path is 0 -> 1 -> 2 -> 3 -> 4 with total time 5 + 2 + 1 + 3 = 11.

Input: (3, [], 0, 2)

Expected Output: -1

Explanation: There are no roads, so node 2 is unreachable from node 0.

Input: (4, [(0,1,7),(1,2,5)], 2, 2)

Expected Output: 0

Explanation: If start and end are the same node, the travel time is 0.

Input: (4, [(0,1,10),(0,1,3),(1,2,4),(0,2,20),(2,3,1)], 0, 3)

Expected Output: 8

Explanation: There are two roads from 0 to 1. Using the cheaper one gives path 0 -> 1 -> 2 -> 3 with total time 3 + 4 + 1 = 8.

Input: (4, [(0,1,0),(1,2,0),(0,2,5),(2,3,2)], 0, 3)

Expected Output: 2

Explanation: The best route is 0 -> 1 -> 2 -> 3 with total time 0 + 0 + 2 = 2.

Hints

  1. Because road times can vary, a normal BFS is not enough. Think about the shortest-path algorithm for graphs with non-negative edge weights.
  2. Use a min-heap to always expand the node with the smallest known travel time, and keep an array of best distances found so far.
Last updated: May 7, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,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
  • 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

  • Expand Nested Repetition Expressions - Waymo (medium)
  • Find Shortest Paths to Target Nodes - Waymo (medium)
  • Implement Safe Average Function - Waymo (medium)
  • Serialize Expression Tree Minimizing Parentheses - Waymo (medium)
  • Find Shortest Knight Path - Waymo (medium)