The TransCompilator

Solved LeetCode program · 172 of 1,000

#0199 · Binary Tree Right Side View

Medium Depth-First Search chunk-04.md

Original English source

Keep a shared values holding 1, 2, 3, -1, 5, -1, and 4. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, -1, -1, and -1.

The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1. The remaining is 1. The nextcount is 0.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. If item node of lefts is at least 0, Place item node of lefts into queue, add 1 to count, add 1 to nextcount. If item node of rights is at least 0, Place item node of rights into queue, add 1 to count, add 1 to nextcount. Subtract 1 from remaining. If remaining is 0, show item node of values, set remaining to nextcount, set nextcount to 0.

Open in Playground Browse all 1,000 problems

Expected stdout

1
3
4