shlogg · Early preview
Md Ariful Haque @mah-shamim

Most Profitable Path In A Tree

Alice's max net income is 6 when she travels towards node 4 in the tree with edges [[0,1],[1,2],[1,3],[3,4]] and amount [-2,4,2,-4,6].

2467. Most Profitable Path in a Tree
Difficulty: Medium
Topics: Array, Tree, Depth-First Search, Breadth-First Search, Graph
There is an undirected tree with n nodes labeled from 0 to n - 1, rooted at node 0. You are given a 2D integer array edges of length n - 1where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.
At every node i, there is a gate. You are also given an array of even integers amount, where amount[i] represents:

the price needed to open the gate at node i, if amount[i] is negative, or,
the cash reward obtained on opening the gate at nod...