Queries to calculate sum of the path from root to a given node in given Binary Tree | Function to find the sum of the path from root to the current node ; Sum of nodes in the path ; Iterate until root is reached ; Update the node value ; Print the resultant sum ; Function to print the path sum for each query ; Traverse the queries ; arraylist to store integers
def sumOfNodeInAPath ( node_value ) : NEW_LINE INDENT sum_of_node = 0 NEW_LINE while ( node_value ) : NEW_LINE INDENT sum_of_node += node_value NEW_LINE node_value //= 2 NEW_LINE DEDENT print ( sum_of_node , end = " ▁ " ) NEW_LINE DEDENT def findSum ( Q ) : NEW_LINE INDENT for i in range ( len ( Q ) ) : NEW_LINE INDENT node_value = Q [ i ] NEW_LINE sumOfNodeInAPath ( node_value ) NEW_LINE print ( end = " " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 5 , 20 , 100 ] NEW_LINE findSum ( arr ) NEW_LINE