LeetCode 235. Lowest Common Ancestor of a Binary Tree in Java

In this post we will solve LeetCode 235. Lowest Common Ancestor of a Binary Tree problem using Java.

Given a binary search tree (BST), 
find the lowest common ancestor (LCA) of two given nodes in the BST.

According to the definition of LCA on Wikipedia: 
“The lowest common ancestor is defined between two nodes p and q 
as the lowest node in T that has both p and q as descendants 
(where we allow a node to be a descendant of itself).”


o The number of nodes in the tree is in the range [2, 10^5].
o -10^9 <= Node.val <= 10^9
o All Node.val are unique.
o p != q
o p and q will exist in the BST.

Realated Topics:

o Tree
o Depth-First Search
o Binary Search Tree
o Binary Trea

We are given a Binary Search Tree (BST) and the pointers / references to two nodes in the tree. We need to return the Lowest Common Ancestor (LCA) node. Continue reading “LeetCode 235. Lowest Common Ancestor of a Binary Tree in Java”

Lowest Common Ancestor of a Binary Tree

Things might be getting somewhat more complex with the COVID-19 pandemic that started in Wuhan, China. The CDC has been posting articles stating that individuals, who have recovered from COVID-19, may be prone to reinfection after three months. The theory of herd immunity, without a vaccine, goes out the door.

On a side note, people in the city of Wuhan, China have been celebrating that coronavirus is receding (there is no way to find out with data what is actually happening there) in their city with a massive water park party. The Chinese Communist Party does not seem to accept responsibility for the 800,000 deaths globally which they allowed to happen and are taking advantage of it in different ways. Continue reading “Lowest Common Ancestor of a Binary Tree”

Lowest Common Ancestor in Binary Search Tree

It is a beautiful sunny summer day in the Twin Cities of Minneapolis and St. Paul. The high temperature for today in the city I live is forecasted to be 83 F. I prefer high temperatures in the range of 75 F to 80 F, but 83 F will have to do.

Yesterday I spent a few hours in front of my computers. My wife left early with a friend to go walking and shopping. My wife got back shortly after 11:00 AM. We made some potatoes with veggies in the grill using a cast iron pan. We always add some pepper, salt and a splash of oil with a high smoke point (i.e., avocado or peanut). Continue reading “Lowest Common Ancestor in Binary Search Tree”