Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Convert Sorted Array to Binary Search Tree

XPChallenge Points: 10
levelLevel: Easy

You are given an integer array nums, where the elements are sorted in ascending order.
Your task is to convert this sorted array into a height-balanced Binary Search Tree (BST).
A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than 1.
Your goal is to construct and return the root node of the height-balanced BST.

Example 1:

Input: nums = [-8, -4, 0, 3, 7, 10]

Output: [3, -4, 7, -8, 0, 10]

Example 2:

Input: nums = [2, 5, 8, 12, 14]

Output: [8, 5, 12, 2, null, null, 14]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result