Convert Binary Tree to Doubly Linked List

Convert a given binary tree to a doubly-linked list.

Statement

Convert a given binary tree to a doubly-linked list, such that the order of the doubly-linked list is the same as the in-order traversal of the binary tree.

After conversion, the left pointer of the node should point to the previous node in the doubly linked list, and the right pointer should point to the next node in the doubly linked list. The head node of the linked list must be the first node in the in-order traversal of the original binary tree.

Example

Consider the binary tree below:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.