Given two binary search tree bst1 and bst2 of size n and m, write a program to return an array of integers containing elements of both BST in non-decreasing order.

Problem Note

  • The expected time complexity is O(m+n).

Example 1

Input:      5            7        
           / \          / \
          3   8        2   9
Output: [2, 3, 5, 7, 8, 9]

Example 2

Input:      1            5        
             \          / \
              4        2  10
Output:[1, 2, 4, 5, 10]