Inorder traversal of BST will give us a sorted array


#1
int k = 0;
 void inorder(TreeNode* root,int B,int &ans){
     if(root==NULL){
         return ;
     }
     inorder(root->left,B,ans);
     k++;if(k==B) ans = root->val;
     inorder(root->right,B,ans);
     
     return ;
 }
 
int Solution::kthsmallest(TreeNode* A, int B) {
    k = 0;
    int ans = -1;
    inorder(A,B,ans);
    return ans;
}