⭐ Simple Solution, easy to understand approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\uD83D\uDC51 Let\'s keep it simple and short.\n\nThe inorder traversal of a BST, will a
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\uD83D\uDC51 Let\'s keep it simple and short.\n\nThe inorder traversal of a BST, will always be sorted if the tree is a valid BST. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIf you think about the intution of this approach, it is simple, we just have to traverse the tree using Inorder and store elements, in an array, and after that we can return the k-1th element from that array, \nor \nwe can keep track of the element from smallest to largest, using an integer variable.\n\n# Complexity\n- Time complexity: O(N) time for traversing the tree.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)+O(H)Aux;\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n\n    // Simple inorder traversal.\n    void inorder(TreeNode* root, vector<int>&res) {\n        if(!root) return;\n        inorder(root->left, res);\n        res.push_back(root->val); // storing root\'s val in res.\n        inorder(root->right, res);\n    }\n\n    int kthSmallest(TreeNode* root, int k) {\n        vector<int> res;\n        inorder(root, res);\n\n        return res[k-1]; // return k-1th element from res;\n    }\n};\n```
['Binary Search', 'Binary Indexed Tree', 'Recursion', 'C++']