Well Explaned || DFS || INORDER || 0ms ||100% (^///^)
\nclass Solution \n{\n    public void inorderSolve(TreeNode root, int k, int[] result)//BST inorder is ascendingly sorted \n    {\n        if(root == null)//Bas
```\nclass Solution \n{\n    public void inorderSolve(TreeNode root, int k, int[] result)//BST inorder is ascendingly sorted \n    {\n        if(root == null)//Base Condition \n            return;\n        \n        inorderSolve(root.left, k, result);//Recursing the Left side of the tree\n        \n        result[0]= result[0] + 1;//increamenting the of index \n        \n        if(result[0] == k){//when the required index is found \n            result[1]= root.val;//Storing the value with the value present at kth index & -1 is for index out of bound \n            return;\n        }\n        \n        inorderSolve(root.right, k, result);//Recursing the Right side of the tree\n        \n        return;//returning to the callinng function \n    }\n    public int kthSmallest(TreeNode root, int k) \n    {\n        int[] result= {0, -1};\n        \n        inorderSolve(root, k, result);//calling the inorder function to get the samllest kth element \n        \n        return result[1];//if the index is out of bound then -1 is returned, else the value is returned \n    }\n}\n```\n<hr>\n<hr>\n\n***Time complexity : O(N) to build a traversal.***\n***Space complexity : O(N) to keep an inorder traversal.***\n\n<hr>\n<hr>\n
['Java']