Network Delay Time

Medium

Network Delay Time

Problem Statement

There are

n
network nodes, and they are labeled from
0
to
n-1
. You are given the following information:

  • A list of
    m
    edges, where each edge is described by an array of three integers
    [source, destination, weight]
    . These edges represent the connections between the network nodes.
  • You are also given an array
    time
    of length
    n
    , where
    time[i]
    represents the time taken to traverse from node
    i
    to all other nodes.

You need to calculate the minimum time it takes for all nodes to receive information. If the network is disconnected, return

-1
.

Rules and Constraints

  • The graph is represented as an adjacency list where each node has a weight (time) associated with it.
  • The weight (time) associated with an edge is considered to be the weight of the edge instead of the edge's capacity.
  • The input graph may contain self-loops and multiple edges between the same pair of nodes, but the weight will only be considered once.
  • You must consider that the weight of the edges may not be symmetric.
  • The network nodes are numbered from
    0
    to
    n-1
    .

Complexity Constraints

  • The time complexity of your solution should be
    O(m + n log n)
    in the worst case.

Example

Input: {"input_data":[1,2,3]} Output: [1,2,3]

CompaniesGoogleMetaAmazon
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.