maxSum
to a large negative value and ans
to 1.level
to 0.level
.
b. Initialize sumAtCurrentLevel
to 0.
c. For each node at the current level (using the size of the queue):
i. Dequeue the node from the queue.
ii. Add the node's value to sumAtCurrentLevel
.
iii. Enqueue the node's children (if any) to the queue.
d. If sumAtCurrentLevel
is greater than maxSum
, update maxSum
and ans
with the current level.ans
.