leetle

Daily challenge for 2026-01-09

374. Smallest Path Sum in Directed Acyclic Graph

Given a directed acyclic graph (DAG) represented by an adjacency list where each edge has a weight, find the path from a specified starting node to a specified ending node that yields the minimum total weight sum. If no path exists, return -1.

Assume nodes are labeled from 0 to N-1. The input graph structure is an adjacency list where graph[u] is a list of [v, weight] pairs, representing an edge from u to v with the given weight.

Example:
Input: N=4, graph=[[[1, 3], [2, 1]], [[3, 2]], [[3, 5]], []], start=0, end=3
Output: 5 (Path 0 -> 2 -> 3 with sum 1 + 5 = 6 is incorrect. Path 0 -> 1 -> 3 with sum 3 + 2 = 5 is correct.)

Run this challenge interactively in Python or JavaScript when the app loads.