Snippets Collections
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);
    }
};
star

Fri Oct 13 2023 03:51:39 GMT+0000 (Coordinated Universal Time) https://practice.geeksforgeeks.org/problems/floor-in-bst/1

#bst #binarysearchtree #floor

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension