Function to find the sum of the node which are present at the maximum depth . While traversing the nodes compare the level of the node with max_level ( Maximum level till the current node ) . If the current level exceeds the maximum level , update the max_level as current level . If the max level and current level are same , add the root data to current sum .
def sumOfNodesAtMaxDepth ( ro , level ) : NEW_LINE INDENT if ( ro == None ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( level > max_level [ 0 ] ) : NEW_LINE INDENT sum [ 0 ] = ro . d NEW_LINE max_level [ 0 ] = level NEW_LINE DEDENT elif ( level == max_level [ 0 ] ) : NEW_LINE INDENT sum [ 0 ] = sum [ 0 ] + ro . d NEW_LINE DEDENT sumOfNodesAtMaxDepth ( ro . l , level + 1 ) NEW_LINE sumOfNodesAtMaxDepth ( ro . r , level + 1 ) NEW_LINE DEDENT