30:00
Given the roots of two binary search trees, root1 and root2, return a list containing every value from both trees sorted in ascending order.
The number of nodes in each tree is in the range [0,5000][0, 5000][0,5000].
−105≤Node.val≤105-10^5 \leq \text{Node.val} \leq 10^5−105≤Node.val≤105
Run code to see results.
Both trees are BSTs, so an inorder walk of each yields sorted values. Walk them side by side and merge, like merging two sorted lists.
tree 1
stack 1
empty
tree 2
stack 2
compare tops
out (0)
[]
Given two binary search trees, return every value from both of them in one ascending list, keeping duplicates.