Longest Path in Network

Company: MediBuddy_8oct

Difficulty: medium

Problem Statement

Longest Path in Network Problem Description A network has N nodes, labelled 1 to N , and M one-way connections. Each connection goes from node u to node v and carries a weight w , which may be negative. The network is a Directed Acyclic Graph: following connections in their direction can never bring you back to a node you have already visited. A path starts at any node and follows connections in their direction. Its total weight is the sum of the weights of the connections it uses. A path may also be a single node that uses no connection; its total weight is 0 . (inferred -- the source says "If no path exists, return 0" and allows negative weights; a single node counts as a path of weight 0, so the answer is never negative. The stored reference of the original question computes exactly this.) Find the largest total weight over all paths in the network. The path may start and end at any nodes. Complete the function longestPathInDAG(N, M, edges) , which returns that largest total weight.