sum
and count
variables to 0.
c. For each node in the current level (current queue):
i. Add the node's value to sum
.
ii. Increment count
.
iii. Enqueue the node's children to the temporary list.
d. Calculate the average for the current level as sum / count
.
e. Add the average to the result list.
f. Replace the queue with the temporary list for the next level.