• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 14, 2023 |1.7K Views
PROBLEM OF THE DAY: 13/10/2023 | Floor in BST
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. 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 Binary Search Tree but will also help you build up problem-solving skills.

In this problem, we are given, a BST(Binary Search Tree) with n number of nodes and value x. Your task is to find the greatest value node of the BST which is smaller than or equal to x.
Note: when x is smaller than the smallest node of BST then returns -1.

Example:

Input:
n = 7               2
                    \
                     81
                   /     \
                42       87
                  \       \
                   66      90
                  /
                45
x = 87

Output:
87

Explanation:
87 is present in tree so floor will be 87.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/floor-in-bst/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/4d4ce38f-e871-43ac-962a-a1429a3ab65b