[Python3] math-ish
\n\nclass Solution:\n    def numOfWays(self, nums: List[int]) -> int:\n        \n        def fn(nums): \n            """Post-order traversal."""\n            if
\n```\nclass Solution:\n    def numOfWays(self, nums: List[int]) -> int:\n        \n        def fn(nums): \n            """Post-order traversal."""\n            if len(nums) <= 1: return len(nums) # boundary condition \n            ll = [x for x in nums if x < nums[0]]\n            rr = [x for x in nums if x > nums[0]]\n            left, right = fn(ll), fn(rr)\n            if not left or not right: return left or right\n            ans = comb(len(rr)+len(ll), len(rr))\n            return ans*left*right\n            \n        return (fn(nums)-1) % 1_000_000_007\n```
['Python3']