Solution:
Get the sorted values of both BSTs in O(m) + O(n), by doing in-order traversal of each BST.
Merge the two sorted arrays in O(m+n).
Create a balanced BST from sorted array in O(m+n).
http://www.geeksforgeeks.org/archives/18611
Get the sorted values of both BSTs in O(m) + O(n), by doing in-order traversal of each BST.
Merge the two sorted arrays in O(m+n).
Create a balanced BST from sorted array in O(m+n).
http://www.geeksforgeeks.org/archives/18611
No comments:
Post a Comment