Longest Path | Dynamic Programming

Given a directed acyclic graph (DAG), compute the longest path that the graph contains. For the purposes of this question, a path is defined by the edges and the input graph is in the form of a list of lists where the list at index i in the array represents each of the connections formed by node i. The number of nodes is guaranteed to not exceed 100000.

Example:

Input:

Output: 2

Try it yourself

โ†
โ†‘๐Ÿช„