No pascal's triangle or yang or combinatoral formula. Simple dp accepted and faster than 60%
1) For the given list, 1st number is the root. Make a list of smaller and bigger numbers after this. And do the following recursively for each of them.\n2) We n
1) For the given list, 1st number is the root. Make a list of smaller and bigger numbers after this. And do the following recursively for each of them.\n2) We need to merge bigger and smaller list together in a way that relative ordering of the number is maintained.\n```\n\'\'\'\nAssume dp[i][j] as the number of ways to put two lists of length i and j together while preserving relative order. Then you can either pick 1 element of i or 1 element of j. Therefore: \n\'\'\'\ndp[i][j] = dp[i-1][j] + dp[i][j-1]\ndp[0][x] = 1\ndp[x][0] = 1\n```\n\n\n```\nclass Solution:\n    \n    def finddp(self, m, n):\n        dp = [[0 for j in range(n+1)] for i in range(m+1)]\n        for i in range(m+1):\n            dp[i][0] = 1\n        \n        for j in range(n+1):\n            dp[0][j] = 1\n        \n        \n        for i in range(1, m+1):\n            for j in range(1, n+1):\n                dp[i][j] = dp[i-1][j] + dp[i][j-1]\n        return dp\n                \n        \n        \n    def numOfW(self, nums: List[int], dp) -> int:\n        if len(nums) == 0:\n            return 1\n        bigger = []\n        smaller = []\n        for n in nums[1:]:\n            if n > nums[0]:\n                bigger.append(n)\n            elif n < nums[0]:\n                smaller.append(n)\n                \n        ans = dp[len(bigger)][len(smaller)]\n        x = 1\n        if len(bigger):\n            x = self.numOfW(bigger, dp)\n        \n        if len(smaller):\n            x *= self.numOfW(smaller, dp)\n            \n        ans = ans * x\n        return ans\n    \n    def numOfWays(self, nums: List[int]) -> int:\n        x = self.finddp(len(nums), len(nums))\n        return self.numOfW(nums, x) % (10**9 + 7) - 1\n```
[]