Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktoptrees · dfs · dynamic-programming
The organizer’s problem statement is available at the official source link.
ancestor path
Compare an ancestor’s wealth with a descendant’s
Every candidate pair lies on one root-to-leaf path, so retain the greatest ancestor value seen above each employee. Schematic structure only; vertices and edges represent the task relation, not an official sample. Schematic graph only; labels and edges show the task relation, not an official sample.
- 1
Traverse the hierarchy
Traverse the management tree from its root. - 2
Track path maximum
At each node, compare its wealth with the highest wealth among strict ancestors. - 3
Update disparity
Update the best disparity and pass the path maximum to its children.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.