Java | Inorder | Explained
Idea: kth smallest element in a BST is the kth item in its inorder traversal because IOT of a BST gives the element in increasing order.\n>T/S: O(h + k)/O(h), w
**Idea:** kth smallest element in a BST is the kth item in its inorder traversal because IOT of a BST gives the element in increasing order.\n>**T/S:** O(h + k)/O(h), where h = height of BST\n```\npublic int kthSmallest(TreeNode root, int k) {\n\tvar kSmallest = new int[1];\n\tinorder(root, new int[]{k}, kSmallest);\n\treturn kSmallest[0];\n}\n\nprivate void inorder(TreeNode root, int[] count, int[] kSmallest) {\n\tif (root == null || count[0] == 0)\n\t\treturn;\n\t// recurse left\n\tinorder(root.left, count, kSmallest);\n\t// visit\n\tif (--count[0] == 0)\n\t\tkSmallest[0] = root.val;\n\telse\n\t// recurse right\n\t\tinorder(root.right, count, kSmallest);\n}\n```\n***Please upvote if this helps***
['Java']