Network Delay Time Problem Statement

Given a network of nodes numbered from 1 to 'N', and 'M' edges. Each edge is represented by three values (u, v, w) where 'u' and 'v' are nodes, and 'w' is an integer representing the time it takes for a signal to travel from 'u' to 'v'. You need to find the time it takes for a signal to travel from a given source node 'K' to all other nodes. Return -1 if it is impossible for the signal to reach all nodes.

Example:

Input:
T = 1
N = 4, M = 4, K = 2
Edges: (2,1,1), (2,3,1), (3,4,1), (4,2,1)
Output:
3
Explanation:

Starting from node 2, it takes 1 unit to reach node 1, 1 unit to reach node 3, and the signal takes a total of 3 units to reach all nodes.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 3000
  • 0 <= M <= 10000
  • 1 <= u, v, K <= N
  • 0 <= w <= 10000
  • Time limit: 1 sec
Be the first one to answer
Add answer anonymously...
ShareChat Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter