Company: Google_8nov
Difficulty: medium
Sum all nodes Problem Description You are given a binary tree with N nodes, numbered from 1 to N and rooted at node 1. Let us define some functions over a node v. Let S(v) be the sum of values of all the nodes whose ancestor is node v. Let S_v(v) be the sum of values of all the nodes on the simple path between node v and node 1 inclusive. Let F(v) = |S(v) - S_v(v)| Let A i denote the value of node i. Let C p denote the left child of the p th node, and C p denote the right child of the p th node. If there is no child on some side, then it would be denoted by -1. Task Calculate the sum of F(v) for all v from 1 to N. Notes 1 based indexing is followed. |x| is the absolute value of x. Function Description Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the answer. N : Represents the size of array A A : Represents an array of integers of size N C : Represents a 2D array of size N (N rows, 2 columns for left/right child) Input Fo