Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Network Recovery Pathways

XPChallenge Points: 30
levelLevel: Hard

You are given a directed acyclic graph with n nodes numbered from 0 to n-1. Each directed edge has an associated repair cost. Some nodes may not be accessible (offline), but node 0 and node n-1 are always available.

We want to travel from node 0 to node n-1. A path is considered valid if:

  1. Every node on the path (except the endpoints) is online.

  2. The sum of all edge costs on this path does not exceed the value k.

For each valid path, define its value as the smallest edge cost in that path.
Return the maximum such value among all valid paths.
If no valid path exists, return -1.

Example 1:

Input: edges = [[0,1,2],[1,2,2],[2,3,1]], online = [true,false,true,true], k = 10

Output: -1

Explanation:

Node 1 is offline, so no valid path exists.

Example 2:

Input: edges = [[0,1,4],[1,2,8],[0,3,5],[3,2,4]] online = [true,true,true,true] k = 12

Output: 4

Explanation:

Valid path: 0 → 3 → 2, total cost = 5 + 4 = 9 ≤ 12. Path score = min(5, 4) = 4. Other paths exceed cost or are worse.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result