Skip to content

Practice Minimum Time to Reach Destination in Directed Graph

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3604
LeetCode Problem

Minimum Time to Reach Destination in Directed Graph

Problem Statement

Start at node 0 at time zero in a directed graph. An edge [u, v, start, end] may be entered only at an integer time in the inclusive interval [start, end], and traversing it takes one time unit. You may instead wait one time unit at your current node. Return the earliest arrival time at node n - 1, or -1 if unreachable.

Source: Minimum Time to Reach Destination in Directed Graph on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 3, edges = [[0,1,0,1],[1,2,2,5]]
Output
3

# Example 2

Input
n = 4, edges = [[0,1,0,3],[1,3,7,8],[0,2,1,5],[2,3,4,7]]
Output
5

# Example 3

Input
n = 3, edges = [[1,0,1,3],[1,2,3,5]]
Output
-1

Constraints

1 <= n <= 10^5
0 <= edges.length <= 10^5
edges[i] == [ui, vi, starti, endi]
0 <= ui, vi <= n - 1
ui != vi
0 <= starti <= endi <= 10^9

Related LeetCode Problems

Practice more problems similar to Minimum Time to Reach Destination in Directed Graph.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.