You are waiting for the assignment problems to appear on OJ. To make sure you spend your…
- User
You are waiting for the assignment problems to appear on OJ. To make sure you spend your time constructively, W.W. comes up with the following task. Define noise of a tree as the sum of values of all its nodes. Find the minimum noise lite subtree of a given binary tree. A lite tree is a rooted binary tree whose inorder traversal is always sorted - either in ascending or in descending order. For e.g. A lite tree with total noise −11. 1.1 Input The first line contains a single integer t(1 ≤ t ≤ 100) - the number of testcases. The first line of each testcase contains a single integer n - the number of elements in the level order traversal array of the tree. (https://en.wikipedia.org/wiki/Tree_traversal#Breadth-first_ search_2) The second line of the test case contains n(1 ≤ n ≤ 104 ) space-separated integers k1, k2, . . . , kn, (−4 × 104 ≤ ki ≤ 4 × 104 ) the elements of the level order array. If ki = 0, it means that the corresponding node is NULL. Otherwise, the corresponding node i contains a value ki . So, a node can take all values {−104 , .., −1, 1, ..., 104}. Please refer to the description of test cases in the next page for more clarity. Note: You must delete the tree at the end of each test case and create a new tree for the next test case. 1.2 Output Print the minimum noise possible in any lite subtree of the given tree. 1 1.3 Example Input Output 3 3 -4 -5 -2 -11 1 2 2 15 4 8 0 6 1 9 0 -5 4 0 0 0 -3 0 10 -8 Let’s consider test case 3. The tree will be constructed by sequentially going over the elements of the array like this Finally, the minimum noise comes out to be −8.
- Assistant
- User
code cgiv
- Assistant
- User
code in c
- Assistant
- User
give full code including the code to check if it is lite tree
- Assistant