Question: Cradle Point , Recent Online Assessment (13th September 2023) | Binary Search Tree
0
Entering edit mode

ADD COMMENTlink 14 months ago Delta 2.9k
0
Entering edit mode

Solution

int kthSmallest(TreeNode* root, int& k) {
    if (root) {
        int x = kthSmallest(root->left, k);
        return !k ? x : !--k ? root->val : kthSmallest(root->right, k);
    }
    return 0;
   }
    

 

ADD COMMENTlink 14 months ago suryansh jaiswal • 370

Login before adding your answer.

Similar Posts
Loading Similar Posts