🔥🔥🔥C++ | neat and clean code | rare solution | must watch🔥🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nconst int mod = 1e9+7;\nvector<int> pascals[1000];\nclass Solution {\nprivate:\n    int solver(vector<int> nums, vector<int> pascals[]){\n        int n = nums.size();\n        if(n < 3) return 1;\n\n        vector<int> left;\n        vector<int> right;\n\n        for(int i=1; i<n; i++){\n            if(nums[i] < nums[0]) left.push_back(nums[i]);\n            else right.push_back(nums[i]);\n        }\n\n        int left_ways = solver(left,pascals);\n        int right_ways = solver(right,pascals);\n\n        return ((1LL * pascals[n-1][left.size()] * left_ways%mod)%mod * right_ways%mod)%mod;\n    }\npublic:\n    int numOfWays(vector<int>& nums) {\n        if(pascals[0].size() == 0){\n            for(int i=0; i<1000; i++){\n                vector<int> temp(i+1,1);\n                pascals[i] = temp;\n                for(int j=1; j<i; j++){\n                    pascals[i][j] = (pascals[i-1][j-1]%mod + pascals[i-1][j]%mod)%mod;\n                }\n            }\n        }\n        return solver(nums,pascals) - 1;\n    }\n};\n```
['Array', 'Math', 'Divide and Conquer', 'Binary Search Tree', 'C++']