Floor in BST
Properties and Validation DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Finding the floor of a given key in a Binary Search Tree (BST), Binary Search Tree, Tree Traversal, Iteration, Time Complexity, Space Complexity, Algorithm, complexity analysis, iterative search, binary search tree operations, search algorithms, binary search tree, tree traversal, Ceil & Floor in BST, Searching.
Problem Statement Given the root of a Binary Search Tree (BST) and an integer key, find the floor of the key in the BST. The floor of a key is defined as the largest node value in the BST that is less than or equal to the key. If no such node exists (i.e., all nodes are greater than the key), return 1. Input Format The first line contains a sequence of integers representing the Binary Search Tree in a level order traversal. A value of 1 indicates a null node. The second line contains a single integer, key. Output Format Return an integer representing the floor of the key. If no floor exists, return 1. Sample Test Cases Example 1: Example 2: