Terrible LeetCode in Kotlin:

Опубликовано: 20 Сентябрь 2026
на канале: Personal Finance with Raymond
24
0

Another day, another LeetCode question (for now). Today, I'm running through #236 Lowest Common Ancestor of a Binary Tree. The problem provides a root tree node, as well as two target nodes, in which you are to find a tree node which is the lowest common ancestor of both. My initial approach was top-down, getting the sets of both left and right subtrees, and using a similar approach to my previous solution to "Lowest Common Ancestor of a Binary Search Tree", but this approach took too long and ran out the clock on LeetCode, even with some additional optimizations. I thought about it some more, but couldn't come to a solution and peeked at the solution on LeetCode. I then redid the problem following the "ancestor set" strategy highlighted by the solution, and solved the problem.

I work in Kotlin as my LeetCode programming language because my current focus is on Android app development. Kotlin is interoperable with Java, so the solution should be relatively similar albeit with some more boilerplate checks for nulls and such.

Current Grind:
Grind75 list, 22 weeks/7 hours per week, [60/169] (51 will be uploaded eventually)
(https://www.techinterviewhandbook.org...)

Chapters:
00:00 - Problem discussion, attempt using left, right sets
37:14 - Solution peek, set of ancestors