Easy C++ Ways to Split Array Into Three Subarrays
\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int n = nums.size(), mod = 1e9 + 7;  long long ans = 0;\n        vector<int> pref
```\nclass Solution {\npublic:\n    int waysToSplit(vector<int>& nums) {\n        int n = nums.size(), mod = 1e9 + 7;  long long ans = 0;\n        vector<int> prefix(n);\n        partial_sum(nums.begin(), nums.end(),prefix.begin());\n        for (int i = 0; i < n - 2; i++) {\n            int left = prefix[i], remain = (prefix[n - 1] - prefix[i]);\n                if (remain < left * 2) break;\n            int leftPtr = lower_bound(prefix.begin() + i + 1, prefix.end() - 1, left * 2) - prefix.begin();\n            int rightPtr = upper_bound(prefix.begin() + i + 1, prefix.end() - 1, left + remain / 2) - prefix.begin() - 1;\n\n            if (rightPtr - leftPtr + 1 > 0) ans += rightPtr - leftPtr + 1;\n        }\n        \n        return ans % mod;\n    }\n};\n```\n# Quick Explanation\n```\nStep 1. Initilise n= size of vector and ans=0 and mod = 1e9 +7\nStep 2. Create a prefix sum vector name prefix\nStep 3. Loop thourgh the prefix vector\nStep 4. Calculate Lower bound of prefix[i] and Upper bound of prefix[i] + (prefix[n-1] - prefix[i])/2\nStep 5. If difference of UB and LB +1 is positive then add them to answer.\nStep 6. return ans with moduls\n```
['C']