Binary Tree

Given a level K, you have to find out the sum of data of all the nodes at level K in a binary tree.

For example :

                                           0
                                         /   \
                                       5      7
                                      /  \     /  \
                                     6   4  1   3
                                            \
                                             9

Tree was given in the form: (node value(left subtree)(right subtree))
For tree given above: (0(5(6()())(4()(9()())))(7(1()())(3()())))
Input format: K and Tree in string format
Output format: Sum
For example, for given tree:
Input: 2 (0(5(6()())(4()(9()())))(7(1()())(3()())))
Output: 14

Author: Amit Khandelwal 1
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer