2 beginner friendly JS Solutions with InOrder and PreOrder traversal
Approach 1:\n\nPreOrder:\nTC:O(n)\nSC: O(log n)\n\n\nvar sortedArrayToBST = function(nums) {\n\t    const helper = (nums, start, end) => {\n        if(end < sta
**Approach 1:**\n\nPreOrder:\nTC:O(n)\nSC: O(log n)\n\n```\nvar sortedArrayToBST = function(nums) {\n\t    const helper = (nums, start, end) => {\n        if(end < start) \n            return null;\n        \n        let mid = start + Math.floor((end - start) / 2);\n        \n        let node = new TreeNode(nums[mid]);\n        node.left = helper(nums, start, mid - 1);\n        node.right = helper(nums, mid+1, end);\n        \n        return node;\n    }\n    \n    return helper(nums, 0, nums.length - 1);\n}\n```\n\n**Approach 2:**\n\nInOrder:\nSC and TC same as Above:\n\n```\nvar sortedArrayToBST = function(nums) {\n\tconst helper = (nums, start, end) => {\n        if(end < start)\n            return null;\n        \n        let mid = start + Math.floor((end - start) / 2);\n        \n        let left = helper(nums, start, mid - 1);\n        \n        let treeNode = new TreeNode(nums[mid]);\n        treeNode.left = left;\n        \n        let right = helper(nums, mid+1, end);\n        treeNode.right = right;\n        \n        return treeNode;\n    }\n    \n    return helper(nums, 0, nums.length - 1);\n}\n```
['JavaScript']