Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Implement a function to calculate the lowest common ancestor in a binary search tree.

Hard

Problem Statement

Implement a function to calculate the lowest common ancestor in a binary search tree.

Sample Input

Tree: 6 / \ 2 8 / \ / \ 0 4 7 9
Nodes: 2 and 8

Sample Output

Lowest Common Ancestor: 6

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
class TreeNode { val: number; left: TreeNode
Log in or sign up to run or submit your code.Log inSign up
Input
Tree: 6 / \ 2 8 / \ / \ 0 4 7 9
Nodes: 2 and 8
Expected Output
Lowest Common Ancestor: 6