Given the root of a binary tree, return the average value of the nodes on each level in the form of an array. Answers within 10^-5 of the actual answer will be accepted.
Example 1
Input: root = [3,9,20,null,null,15,7]
Output: [3.0,14.5,11.0]
Explanation: Level 0 holds only 3, so its average is 3. Level 1 holds 9 and 20: (9 + 20) / 2 = 14.5. Level 2 holds 15 and 7: (15 + 7) / 2 = 11.
Example 2
Input: root = [4,2,6,1,3,5,7]
Output: [4.0,4.0,4.0]
Explanation: Level 0 is [4], level 1 is [2,6] with average 4, and level 2 is [1,3,5,7] with average 16 / 4 = 4. Every level averages to 4.
Example 3
Input: root = [1]
Output: [1.0]
Explanation: The tree has a single level containing just 1, so the answer is [1.0].
Process the tree level by level with a queue. For each level, sum the node values and divide by the count to get that level's average.
Run checks all cases above. Submit evaluates all test cases.