The TransCompilator

Solved LeetCode program · 790 of 1,000

#1026 · Maximum Difference Between Node and Ancestor

Medium Depth-First Search chunk-16.md

Original English source

Keep a shared values holding 8, 3, 10, 1, 6, -1, 14, -1, -1, 4, 7, and 13. Keep a shared lefts holding 1, 3, 5, 7, 9, -1, 11, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, 8, 10, -1, -1, -1, -1, -1, -1, and -1. Keep a shared best of 0.

To search from node (a whole number) with low (a whole number) and high (a whole number). If node is less than 0, return. If item node of values is less than 0, return. The value is item node of values. The floor is low. The ceiling is high. If value is less than floor, set floor to value. If value is more than ceiling, set ceiling to value. The gap is ceiling minus floor. If gap is more than best, set best to gap. Search from item node of lefts with floor and ceiling. Search from item node of rights with floor and ceiling.

Search from 0 with 8 and 8. Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

7