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

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro