give array num represent permutation integer 1 n we go construct binary search tree BST insert element num order initially BST Find number different way reorder num construct BST identical form original array numsfor example give num 213 2 root 1 leave child 3 right child the array 231 yield BST 321 yield different BSTReturn number way reorder num BST form identical original BST form numsSince answer large return modulo 109 7 Example 1input num 213output 1explanation we reorder num 231 yield BST there way reorder num yield BSTExample 2input num 34512output 5explanation the follow 5 array yield BST 3124531425314523412534152example 3input num 123output 0explanation there ordering num yield BST Constraints1 numslength 10001 numsi numslengthAll integer num distinct