947. Convert BST to Sorted Doubly Linked List

HardTreesBSTInorderLinked List

Given the root of a binary search tree, convert it in place to a sorted circular doubly linked list, where left acts as the previous pointer and right as the next pointer. Return the sequence of values in the list order (ascending), which is the BST's inorder traversal, as an array. The tree is given as a level-order BST array.

Input: A level-order BST array.

Output: Array — the values in doubly-linked-list (ascending) order.

Examples

Example 1
Input: [4,2,5,1,3]
Output: [1,2,3,4,5]
Explanation: Inorder gives the sorted DLL order.
Example 2
Input: [5]
Output: [5]
Explanation: Single node.
Example 3
Input: []
Output: []
Explanation: Empty tree.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →