C++ Solution | Greedy Approach
Solution:\n\nConsiderig every prefix of the array as the \'left\' subarray count the number of possible \'middle\' subarrays and add them to the final answer.\n
**Solution:**\n\nConsiderig every prefix of the array as the \'left\' subarray count the number of possible \'middle\' subarrays and add them to the final answer.\n\n**Explanation:**\n\n* Make a prefix sum array. \n* Now start traversing the array and assume the sum[i] to be the sum of \'left\' array. \n* The \'middle\' array has to be atleast this sum so use binary search over the prefix sum array to find the starting value\n* The maximum possible value for the \'middle\' array is the (sum of array - left array sum)/2 again find the ending value using the binary search. \n* Having the starting and ending possible indexes of \'middle\' array we will add the count to the final answer.\n```\nint mod = 1e9+7;\n    \n    int waysToSplit(vector<int>& nums) {\n        \n        int i, left, remaining, mid_startpoint, mid_endpoint, max_mid, length, n = nums.size();\n        vector<int>sum(n, 0);\n        \n        long long ans=0;\n        \n        sum[0] = nums[0];\n        for(i = 1; i < n; i++) \n            sum [i] = sum[i-1] + nums[i];\n        \n        for(i = 0; i < n; i++) {\n            \n            left = sum[i];\n            remaining = sum[n-1] - left;\n\n            max_mid = remaining/2;\n                 \n            mid_startpoint = lower_bound(sum.begin() + i + 1, sum.end(), sum[i] + left) - sum.begin();\n            \n            // have to apply search upto n-1 otherwise an empty right part will also be counted\n            mid_endpoint = upper_bound(sum.begin() + i + 1, sum.begin() + n - 1  , sum[i] + max_mid) - sum.begin();\n            mid_endpoint--;\n\n            length = (mid_endpoint - mid_startpoint + 1);\n            \n            ans += max(0, length);\n            \n        }\n        \n        return ans % mod;\n    }\n```\n
[]