Two JS Solutions
\n/*\n1. Inorder traversal of BST represents the numbers in ascending order.\n2. Get the kth element in the inorder traversal.\n*/\nvar kthSmallest = function(r
```\n/*\n1. Inorder traversal of BST represents the numbers in ascending order.\n2. Get the kth element in the inorder traversal.\n*/\nvar kthSmallest = function(root, k) {\n    let res = [];\n    dfs(root, res);\n    return res[k - 1];\n\t// T.C: O(N)\n\t// S.C: O(N)\n};\n\nconst dfs = (root, res) => {\n    if (!root) {\n        return;\n    }\n    dfs(root.left, res);\n    res.push(root.val);\n    dfs(root.right, res);\n}\n```\n\n```\nvar kthSmallest = function(root, k) {\n    let res = null;\n    dfs(root);\n    return res;\n    // T.C: O(H + K)\n    // S.C: O(H)\n    function dfs(root) {\n        if (!root) {\n            return;\n        }\n        dfs(root.left);\n        if (res) {\n            return;\n        }\n        k--; // a node is visited\n        if (k === 0) {\n            res = root.val;\n            return;\n        }\n        dfs(root.right);\n    }\n};\n```
['JavaScript']