2 APPROACHES||EASY||100ms||bst
AN UPVOTE WILL BE HIGHLY APPRECIATED\n```\n//APPROACH 1(ARRAYLIST ONE)\nclass Solution {\n    static ArrayList arr = new ArrayList();\n    \n    static void Pre
AN UPVOTE WILL BE HIGHLY APPRECIATED\n```\n//APPROACH 1(ARRAYLIST ONE)\nclass Solution {\n    static ArrayList<Integer> arr = new ArrayList<Integer>();\n    \n    static void PreeOrder(TreeNode root){\n        if(root == null){\n            return;\n        }\n        arr.add(root.val);\n        PreeOrder(root.left);\n        PreeOrder(root.right);\n    }\n    \n    public int kthSmallest(TreeNode root, int k) {\n        arr = new ArrayList<Integer>();\n        PreeOrder(root);\n        Collections.sort(arr); \n        return arr.get(k-1);\n    }\n}\n\n\n//APPROACH 2(OPTIMIZED ONE)\nclass Solution {\n    int i =1;     //variable to track position of the element\n    int ans = 0;\n    public int kthSmallest(TreeNode root, int k) {\n        inorder(root, k);\n        return ans;\n        \n    }\n    \n    public void inorder(TreeNode root, int k) {\n        if(root == null) {\n            return;\n        }\n        \n        inorder(root.left, k);\n        \n        if(i==k){\n            ans = root.val;    // store root value in ans when i == k\n        }\n        i++;       //increament variable for every call\n        inorder(root.right, k);\n    }\n}\n
['Array', 'Depth-First Search', 'Recursion', 'Java']