Dsa
Trees
Medium
Binary Tree Level Average
Given a binary tree, compute the average value of the nodes on each level. The input format is as follows: the first line contains an integer n (1 <= n <= 1000), which is the number of nodes in the tree, followed by n lines where each line contains an integer value (the value of the node). The nodes are given in Level Order (root first, then left-to-right). The output should be n lines with the average value for each level rounded to two decimal places.
Example Input:
7
3
9
20
null
null
15
7
Example Output:
3.00
14.50
Key concepts
treestraversalaverage
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now