Black height
Standard · Trace the algorithm · about 5 min
The black height of a tree is the number of black nodes on a path from the root down to an empty spot. The root counts. In a valid tree every such path agrees. Follow the check and answer each question.
Example 1
Input:
{"levelOrder":[20,10,30,5,15,25,35,3,null,null,null,22],"colours":["B","B","B","B","B","B","B","R","R"]}
Output:
3
Every path holds 3 black nodes.
Learn the idea first: Red-black trees, a visual lesson.
More Red-black trees problems
- Fix a violation Warm-up
- Valid colorings Standard