Floor in BST | Practice | GeeksforGeeks

PHOTO EMBED

Fri Oct 13 2023 03:51:39 GMT+0000 (Coordinated Universal Time)

Saved by @DxBros #bst #binarysearchtree #floor

class Solution{

public:
    int searchBST(Node* root, int target, int ans = -1){
        if(!root){
            return ans;
        }
        if(root->data <= target){
            ans = root->data;
            return searchBST(root->right,target, ans);
        }
        return searchBST(root->left, target, ans);
        
    }
    int floor(Node* root, int x) {
        // Code here
        if(!root )  return -1;
        return searchBST(root, x);
    }
};
content_copyCOPY

https://practice.geeksforgeeks.org/problems/floor-in-bst/1