Amazon interview question
Taken from here: http://stackoverflow.com/questions/17746207/amazon-interview-quetion
Write a function that computes the maximum sum in a subtree. Print the sum of the subtree with the maximum sum of a binary tree. For the inputs, number of nodes will be the first input and then inorder traversal and preorder traversal of the tree will be given consecutively. You have to form the tree and then find the maximum sum of a subtree within it.
input: 6 4 2 5 1 6 3 1 2 4 5 3 6 Output: 21
Write a function that computes the maximum sum in a subtree. Print the sum of the subtree with the maximum sum of a binary tree. For the inputs, number of nodes will be the first input and then inorder traversal and preorder traversal of the tree will be given consecutively. You have to form the tree and then find the maximum sum of a subtree within it.
input: 6 4 2 5 1 6 3 1 2 4 5 3 6 Output: 21
Comments