The TransCompilator

Solved LeetCode program · 399 of 1,000

#0538 · Convert BST to Greater Tree

Medium Depth-First Search chunk-08.md

Original English source

Keep a shared values holding 4, 1, 6, 0, 2, 5, 7, 3, and 8. Keep a shared lefts holding 1, 3, 5, -1, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, 7, -1, 8, -1, and -1. Keep a shared running of 0.

To boost from node (a whole number). If node is less than 0, return. Boost from item node of rights. The here is item node of values. Add here to running. Set item node of values to running. Boost from item node of lefts.

Boost from 0. The queue is an empty list of whole numbers. Place 0 into queue. The head is 0. The count is 1.
Repeat while head is less than count.
The node is item head of queue. Add 1 to head. Show item node of values. The left is item node of lefts. The right is item node of rights. If left is at least 0, Place left into queue, add 1 to count. If right is at least 0, Place right into queue, add 1 to count.

Open in Playground Browse all 1,000 problems

Expected stdout

30
36
21
36
35
26
15
33
8