DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Graph

Network Delay Time (Dijkstra)

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Network Delay Time (Dijkstra)** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Dijkstra's algorithm with min-heap **Edge Cases to Consider:** - (1) Source unreachable to some node - (2) Single node - (3) Negative weight (Dijkstra fails)

Examples

Example 1
Input: [[2,1,1],[2,3,1],[3,4,1]], 4, 2
Output: 2
Explanation: Classic
Example 2
Input: [[1,2,1]], 2, 1
Output: 1
Explanation: Single edge
Example 3
Input: [[1,2,1]], 2, 2
Output: -1
Explanation: Source can't reach node 1

Constraints

  • ▪2 <= vertices <= 1000
  • ▪0 <= edges <= 5000
  • ▪Avoid infinite cycles during depth traversal

Watch Out For Edge Cases

  • ▪Source unreachable to some node
  • ▪Single node
  • ▪Negative weight (Dijkstra fails)
Frequently Asked At
GoogleAmazonMicrosoftUber