JavaScript Solution for sorted array to balanced bst


#1
sortedArrayToBST: function (A) { 
      
      
      function createTree(arr) {
          if (arr.length == 0) {
              return null
          }
          const midIdx = parseInt(arr.length / 2)
          const root = new TreeNode(arr[midIdx])
          root.val = arr[midIdx]  // while checking solution, the programme is checking for "node.val" instead of "node.data"
          root.left = createTree(arr.slice(0, midIdx))
          root.right = createTree(arr.slice(midIdx+1, arr.length))
          return root
      }
      
      return createTree(A)
      
}