Easiest Explanation | Hard --> Easy | codestorywithMIK
YouTube video link - Number of Ways to Reorder Array to Get Same BST\nMy Github Treasure - Number of Ways to Reorder Array to Get Same BST\n\n\n\nclass Solution
YouTube video link - [Number of Ways to Reorder Array to Get Same BST](https://www.youtube.com/watch?v=YMe9Q2yZvBo)\nMy Github Treasure - [Number of Ways to Reorder Array to Get Same BST](https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Mathematical/Number%20of%20Ways%20to%20Reorder%20Array%20to%20Get%20Same%20BST.cpp)\n\n\n```\nclass Solution {\npublic:\n    typedef long long ll;\n    ll MOD = 1e9 + 7;\n    \n    vector<vector<ll>> PT;\n    \n    int solve(vector<int>& nums) {\n        int m = nums.size();\n        \n        if(m < 3)\n            return 1;\n        \n        vector<int> left, right;\n        \n        int root = nums[0];\n        for(int i = 1; i < m; i++) {\n            \n            if(nums[i] < root) {\n                left.push_back(nums[i]);\n            } else {\n                right.push_back(nums[i]);\n            }\n            \n        }\n        \n        ll leftways  = solve(left)  % MOD;\n        ll rightways = solve(right) % MOD;\n        \n        return (((leftways * rightways)%MOD) * PT[m-1][left.size()]) % MOD;\n        \n    }\n    \n    int numOfWays(vector<int>& nums) {\n        int n = nums.size();\n        \n        \n        PT.resize(n+1);\n        \n        for(int i = 0; i <= n; i++) {\n            \n            PT[i] = vector<long long>(i+1, 1);\n            \n            for(int j = 1; j < i; j++) {\n                PT[i][j] = (PT[i-1][j-1] + PT[i-1][j]) % MOD;\n            }\n        }\n        \n        \n        return (solve(nums)-1) % MOD;\n    }\n};\n```
[]