PROBLEM OF THE DAY: 13/10/2023 | Floor in BST
source link: https://www.geeksforgeeks.org/videos/problem-of-the-day-13102023-floor-in-bst/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
PROBLEM OF THE DAY: 13/10/2023
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
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK