Divide Given Bst

easy
You are given root of a BST and a targat value.
Divide this BST into 2 BST's such that
1) first BST contains all values smaller then and equal to target.
2) second BST contains all values higher then target

Input Format

Root of BST Integer target Note: given tree is balanced so you only need to use inorder traversal for tree generation

Output Format

RootNode of 2 BSTS

Constraints

The number of nodes in the tree is in the range [1, 50].
0 <= Node.val, target <= 1000

Notice

NA

Example

Input
1 2 3 4 5 6 7 8 9
4
Output
1 2 3 4 #5 6 7 8 9 
Previous
Greater Smaller Pointer
Next
Missing Element In Sorted Array

Related Questions