CT025

Build Balanced BST from Sorted List

MediumAcceptance: 0.0%

The Codetikki archivists received a sorted list of scroll IDs and want to build a height-balanced binary search tree from it. Given a sorted array of integers, convert it to a height-balanced BST. Output the level-order traversal of the resulting BST (with "null" for absent nodes). Input: first line n, second line n sorted integers. Output: level-order traversal.

Example 1:

Input: 5 -10 -3 0 5 9
Output: 0 -3 9 -10 null 5

Example 2:

Input: 3 1 2 3
Output: 2 1 3

Constraints:

1 <= n <= 10^4 -10^9 <= arr[i] <= 10^9 Array is sorted in ascending order

Tags:

binary-search-tree trees divide-and-conquer recursion
Loading...
Test Cases:No test cases
No test cases available.
Coding Problem Not Found | CodeTikki