The TransCompilator

Solved LeetCode program · 204 of 1,000

#0235 · Lowest Common Ancestor of a Binary Search Tree

Medium Depth-First Search chunk-05.md

Original English source

Keep a shared values holding 6, 2, 8, 0, 4, 7, 9, 3, and 5. Keep a shared lefts holding 1, 3, 7, 9, -1, 5, 6, -1, and -1. Keep a shared rights holding 2, 4, 8, 10, -1, -1, -1, -1, and -1. The current is 0. The answer is 0. Set answer to -1.
Repeat while answer is -1.
The here is item current of values. The left is item current of lefts. The right is item current of rights. If here is more than 8, set current to left. If here is less than 2, set current to right. If here is at least 2 and here is at most 8, set answer to here.

Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

6