Company: Statestreet_13oct
Difficulty: medium
Sum of Magic Nodes Problem Description Consider a binary tree of N nodes (1 Root and N-1 descendants). A node in this tree is called a 'Magic node' if both its descendants are 'Special numbers'. A Special number is one which reduces to 1 which successively replaced by the sum of the squares of its digits. For example, if n = 23: First iteration: 2 2 + 3 2 = 4 + 9 = 13 Second iteration: 1 2 + 3 2 = 1 + 9 = 10 Third iteration: 1 2 + 0 2 = 1 + 0 = 1 Since we reach 1, hence 23 is a Special number. The tree is represented as a series of relationships of each node to the Root node such as L, R, LL, LR... and so on, where each node is left (L) to Root or left-left (LL) or right-left (RL) to Root and so on. Write a program to find all the Magic nodes in the tree and print the sum of all such Magic nodes. Read the input from STDIN and print the output to STDOUT. Do not write arbitrary strings anywhere in the program, as these contribute to the standard output and testcases will fail. Constraint