• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
April 04, 2024 |490 Views
PROBLEM OF THE DAY : 03/04/2024 | Kth common ancestor in BST
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Siddharth Hazra. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of BST but also build up problem-solving skills.

In this problem, we are given a BST with n (n>=2) nodes, find the kth common ancestor of nodes x and y in the given tree. Return -1 if kth ancestor does not exist.
Nodes x and y will always be present in the input of a BST, and x != y.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://www.geeksforgeeks.org/problems/kth-common-ancestor-in-bst/1