Lowest Common Ancestor — Solution & Editorial
At these limits the walk-up method works: lift the deeper node to equal depth, then lift both together until they meet. (Binary lifting handles bigger limits.)
Complexity: O(Q · depth)
At these limits the walk-up method works: lift the deeper node to equal depth, then lift both together until they meet. (Binary lifting handles bigger limits.)
Complexity: O(Q · depth)