> For the complete documentation index, see [llms.txt](https://ucan.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ucan.gitbook.io/notes/tree/230.-kth-smallest-element-in-a-bst.md).

# 230. Kth Smallest Element in a BST

```java
class Solution {
    int count = 0;
    public int kthSmallest(TreeNode root, int k) {
        // in order trasversal
        if (root==null) return -1;
        int leftVal = kthSmallest(root.left, k);
        if (leftVal>=0) return leftVal;
        count++;
        if(count==k) return root.val;
        return kthSmallest(root.right, k);
    }
}
```
