Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Floor in BST
MEDIUM
30 mins
43 upvotes
Binary Search Trees
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Binary Search Trees
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Floor in BST

Medium
yellow-spark
0/80
Avg time to solve 30 mins
Success Rate 70 %
Share
43 upvotes

Problem Statement

You are given a BST (Binary search tree) with’ N’ number of nodes and a value ‘X’. Your task is to find the greatest value node of the BST which is smaller than or equal to ‘X’.

Note :‘X’ is not smaller than the smallest node of BST .

For example:

1

In the above example, For the given BST  and X = 7, the greatest value node of the BST  which is smaller than or equal to  7 is 6.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
10 5 15 2 6 -1 -1 -1 -1 -1 -1
7
2 1 3 -1 -1 -1 -1
2
Sample Output 1:
6
2
Explanation of Sample Input 1:
In the first test case, the BST looks like as below:

1

The greatest value node of the BST which is smaller than or equal to  7 is 6.

In the second test case, the BST looks like as below:

1

The greatest value node of the BST which is smaller than or equal to  2 is 2.
Sample Input 2:
2
5 3 10 2 4 6 15 -1 -1 -1 -1 -1 -1 -1 -1
15
5 3 10 2 4 6 15 -1 -1 -1 -1 -1 -1 -1 -1
8
Sample Output 2:
15
6
Reset Code
Full screen
Auto
copy-code
Console