you give n BST binary search tree root node n separate bsts store array tree 0indexe each BST tree 3 node root value in operation canselect distinct index j value store leave treesi equal root value treesjReplace leaf node treesi treesjremove treesj treesreturn root result BST possible form valid BST perform n 1 operation null impossible create valid bsta BST binary search tree binary tree node satisfie follow propertyevery node node leave subtree value strictly nod valueEvery node nod right subtree value strictly great node valuea leaf node child Example 1input tree 2132554output 3251null4ExplanationIn operation pick i1 j0 merge trees0 trees1delete trees0 tree 325154in second operation pick i0 j1 merge trees1 trees0Delete trees1 tree 3251null4the result tree show valid BST return rootExample 2input tree 538326output ExplanationPick i0 j1 merge trees1 trees0Delete trees1 tree 53826the result tree show this valid operation perform result tree valid BST return nullExample 3input tree 543output Explanation it impossible perform operation Constraintsn treeslength1 n 5 104the number nod tree range 1 3each node input child grandchildrenNo root tree valueall tree input valid BSTs1 TreeNodeval 5 104