Closed MuhammadTausif closed 1 month ago
class Solution:
def inorder(self,root):
l=[]
def helper(node):
if node is None:
return None
helper(node.left)
l.append(node.data)
helper(node.right)
return l
return helper(root)
def merge(self, root1, root2):
final=self.inorder(root1)+self.inorder(root2)
final.sort()
return final
Merge two BST 's
Link
Difficulty: Medium
Given two BSTs, return elements of merged BSTs in sorted form.
Examples :
*Expected Time Complexity: O((m+n)log(m+n)) Expected Auxiliary Space: O(Height of BST1 + Height of BST2 + m + n)**
Constraints: