Convert Sorted Array to Binary Search Tree
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

30:00

Convert Sorted Array to Binary Search Tree
easy
Topics
Companies

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

Example 1:
Input: {"nums":[-10,-3,0,5,9]}
Output: [0,-10,5,null,-3,null,9]
Constraints:
  • 1nums.length1041 \leq \text{nums.length} \leq 10^4

  • 104nums[i]104-10^4 \leq \text{nums}[i] \leq 10^4

  • nums is sorted in strictly increasing order.

Input
arr ={"nums":[-10,-3,0,5,9]}

Processing range [0, 4]

Sorted Array

-10

0

-3

1

0

2

5

3

9

4
left=0right=4

Tree will be built here

Mid Element
Current Range
Outside Range
Variables
No variables to display
DepthFunction Call
Stack empty
0/36