#K16186. Sum of Nodes at the k-th Level in a Binary Tree
Sum of Nodes at the k-th Level in a Binary Tree
Sum of Nodes at the k-th Level in a Binary Tree
You are given a binary tree and an integer ( k ). The binary tree is represented in level order with the string ( "null" ) denoting a missing node. The root of the tree is at level 0. Your task is to compute the sum of all node values at the ( k )-th level of the tree. If the ( k )-th level does not exist, output 0.
Input Format:\nThe first line contains an integer ( k ). The second line contains a space-separated list of values representing the tree in level order (use the word "null" for missing nodes).\n Output Format:\nOutput a single integer representing the sum of nodes at the ( k )-th level.
Example:\nInput:\n2
1 2 3 4 null 5 6
\nOutput:\n15
inputFormat
The input is read from standard input (stdin) and consists of two lines:\n1. The first line contains the integer ( k ).\n2. The second line contains the level order traversal of the binary tree as space-separated tokens. Use "null" (without quotes) to denote missing nodes.
outputFormat
Print the sum of all node values at the ( k )-th level of the binary tree to standard output (stdout). If the level does not exist, print 0.## sample
0
1
1
</p>