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
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
Top ShareChat Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Reviews
Interviews
Salaries
Users/Month