Wednesday, February 23, 2022

Lowest common ancestor: O(1) space complexity

Feb. 23, 2022 

Lowest common ancestor

I wrote C# code to find lowest common ancestor in a given binary tree, two nodes p and q, and each node has parent node in the definition. 

The following is C# code I wrote. The interviewer shared with me another idea, similar to two linked list will advance to LCA node by building the linked list special way. 


 

No comments:

Post a Comment