Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Network delay time

    Network delay time

    Mediumgraphdijkstraheapshortest path

    There are n devices numbered 0 to n-1. Each [u, v, w] in times means a message from u to v takes w seconds (one way). A message starts at device k. Return the time when every device has received it, or -1 if some device is never reached.

    Example 1

    Input:  times = [[1,0,1],[1,2,1],[2,3,1]], n = 4, k = 1
    Output: 2

    Example 2

    Input:  times = [[0,1,1]], n = 2, k = 1
    Output: -1

    Constraints

    • 1 ≤ n ≤ 100
    • 1 ≤ times.length ≤ 6000
    • 0 ≤ u, v < n, u ≠ v
    • 1 ≤ w ≤ 100
    • No repeated (u, v) pair

    Submit checks your solution against 8 tests, including hidden ones.

    /**
     * @param {int[][]} times
     * @param {int} n
     * @param {int} k
     * @return {int}
     */
    function networkDelay(times, n, k) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.