Problem: Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the meaning of left and right pointers are different. In DLL, left means previous pointer and right means next pointer.
Let the following be input binary tree 1 / \ 2 3 / \ \ 4 5 6 / \ / \ 7 8 9 10 Output: Doubly Linked List 785910 Modified Tree: 1 / \ 2 3 / \ 4 6
This problem is popular in Leetcode and GeeksForGeeks. A collection of hundreds of interview questions and solutions are available in our blog at Interview Question
Solution:
No comments:
Post a Comment