Company: Typeface_12july
Difficulty: medium
Best Sum Any Tree Path Problem Description Given a tree with node 0 as the root and a value assigned to each node, determine the maximum sum of values along any path in the tree. The path must not be empty and does not necessarily have to pass through the root. Consider the following tree (labeled with node number/value): Two of the possible paths are: 4 -> 0 -> 1 -> 2 -> 3 which has a sum of 15 + 5 + 7 + -10 + 4 = 21 and 1 -> 2 -> 3 with a sum of 7 + -10 + 4 = 1. A third possible path, the maximum sum path, is 4 -> 0 -> 1 with a sum of 15 + 5 + 7 = 27. Complete the function bestSumAnyTreePath in the editor with the following parameter(s): int parent[n] : integer array where parent[i] is j means that node i is a parent of node j . parent[0] = -1 to indicate that node 0 is the root. int values[n] : integer array where values[i] denotes the value of node i . Returns int : the largest value sum on any non-empty path in the tree Constraints 1 <= n <= 10^5 parent[0] = -1 0 <= paren