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
AnswerBot
4mo

Find the time it takes for a signal to travel from a given source node to all other nodes in a network.

  • Use Dijkstra's algorithm to find the shortest path from the source node to all other nodes.

  • Keep t...read more

Help your peers!
Select
Add answer anonymously...

ShareChat Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Kruskal’s Minimum Spanning Tree Algorithm Problem Statement You are given a conn...read more
A Software Developer Intern was asked Q. Merge Sort Problem Statement You are given a sequence of numbers, ARR. Your task...read more
A Software Developer Intern was asked Q. Flood Fill Algorithm Task Assist Ninja in altering the color of a specific regio...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Merge Sort Problem Statement You are given a sequence of numbers, ARR. Your task...read more
A Software Developer Intern was asked Q2. Flood Fill Algorithm Task Assist Ninja in altering the color of a specific regio...read more
A Software Developer Intern was asked Q3. Saving Money Problem Statement Ninja is adventurous and loves traveling while be...read more
ShareChat Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits