Convert Binary Search Tree to Sorted Doubly Linked List

Medium

Description

Convert a binary search tree to a sorted circular doubly-linked list in-place. The left pointer is prev, right is next.

Examples

Input:root = [4,2,5,1,3]
Output:[1,2,3,4,5]
Explanation:

In-order traversal.

Input:root = [1]
Output:[1]
Explanation:

Edge case with a single-element array.

Input:root = [10,6,14,4,8,12,16]
Output:[4,6,8,10,12,14,16]
Explanation:

A complete binary search tree with 7 nodes. The in-order traversal visits left subtree, root, then right subtree, producing the sorted sequence. This demonstrates the algorithm working on a balanced, multi-level tree structure.

Constraints

  • 0 ≤ nodes ≤ 2000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!