Python3 - Easy to understand binary search
Approach\n\nI was confused by the existing solutions so I attached the derivations and code that made sense to me, hope it helps.\n\n\nsum_l <= sum_m <= sum_r\n
# Approach\n\nI was confused by the existing solutions so I attached the derivations and code that made sense to me, hope it helps.\n\n```\nsum_l <= sum_m <= sum_r\n\n# sum_j = sum up to smallest mid split end-index\n# sum_k = sum up to largest mid split end-index\n# sum_n = sum of entire array\n\n# Finding sum_j\nsum_l <= sum_m\nsum_l <= sum_j - sum_l\n2*sum_l <= sum_j\nmin(sum_j) = 2*sum_l\n\n# Finding sum_k\nsum_m <= sum_r\nsum_k - sum_l <= sum_n - sum_k\nsum_k <= sum_n - sum_k + sum_l\n2*sum_k <= sum_n + sum_l\nsum_k <= (sum_n + sum_l)/2\nmax(sum_k) = (sum_n + sum_l)/2\n```\n\n\n# Code\n```python\nclass Solution:\n    def waysToSplit(self, nums: List[int]) -> int:\n        prefix = list(accumulate(nums))\n        ans = 0\n        n = len(nums)\n\n        for i in range(n):\n            # find smallest mid split end-index\n            j = bisect_left(prefix, 2 * prefix[i], lo=i+1)\n            # find largest mid split end-index\n            k = bisect_right(prefix, (prefix[i] + prefix[-1]) // 2, hi=n-1)\n            \n            # not valid\n            if j >= k: \n                continue\n\n            ans += k - j\n        return ans % int(1e9 + 7)\n```
['Python3']