Python short and simple
Simple recursion\nNumber of ways of re-arranging current array = (number of ways of rearranging m values of left subtree) * (number of ways of rearranging n val
**Simple recursion**\nNumber of ways of re-arranging current array = (number of ways of rearranging **m** values of left subtree) * (number of ways of rearranging **n** values of right subtree) * (number of ways of inter-leaving two arrays of sizes m and n having unique integers such that order is preserved i.e. **xCy where x = m+n and y = n**).\n\nAt the end, we subtract 1 from the number of all combinations to account for input sequence which itself gives the same tree and should not be counted.\n\nRefer to "Number of ways to interleave two ordered sequences": https://math.stackexchange.com/a/666295\n\n```\nclass Solution:\n    def numOfWays(self, nums: List[int]) -> int:\n        def countWays(nums):\n            if not nums:\n                return 1\n            nums1 = [num for num in nums if num < nums[0]]\n            nums2 = [num for num in nums if num > nums[0]]\n            return countWays(nums1) * countWays(nums2) * math.comb(len(nums1) + len(nums2), len(nums2))\n        \n        return (countWays(nums)-1) % (10**9+7)\n```
[]