Convert BST to Sorted Doubly Linked List
Convert a binary search tree in place into a sorted circular doubly linked list, where left acts as the predecessor pointer and right as the successor pointer. Return a pointer to the smallest element; the list's ends wrap around to each other.
Open official problem prompt ↗Rewire a BST's existing nodes into a sorted, circular, doubly linked list without allocating new nodes.
Walking a sorted bookshelf left to right and clipping each book to the one you just passed, then joining the last book back to the first to form a carousel.
- Input
- root = [4,2,5,1,3]
- Output
- 1 <-> 2 <-> 3 <-> 4 <-> 5 (circular)
- Why
- Inorder order of the BST is 1,2,3,4,5; each node links to its sorted neighbors and 5 wraps back to 1.
The number of nodes is in the range [0, 2000]-1000 <= Node.val <= 1000All values are unique