31. Closest Neighbour in BST
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
int findMaxForN(Node* root, int n) {
if (!root)
return -1;
if (root->key <= n)
return max(root->key, findMaxForN(root->right, n));
return findMaxForN(root->left, n);
}
};Contribution and Support
Last updated