Lowest Common Ancestor with Binary Lifting

hard
Unit 23 · Trees & Graphs0/0 to milestone

For a rooted tree given as a parent array (parent[root] == -1), answer many lowest common ancestor queries in O(log n) each after O(n log n) preprocessing.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Lowest Common Ancestor with Binary Lifting · TechGradify