Grokking Graph Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Solution: Network Delay Time
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given a network of n nodes labeled from 1 to n. You also have a list called times, where each element is a tuple (u, v, w) representing a directed edge from node u to node v with a travel time w.

Determine the minimum time it takes for a signal sent from a given starting node k to reach all other nodes in the network. If it is not possible for the signal to reach all nodes, return -1.

Examples

Example 1:

  • Input: times = [[1, 2, 3], [1, 3, 4], [2, 4, 5], [3, 4, 1]], n = 4, k = 1
  • Expected Output: 5
  • Justification:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible