1712. Ways to Split Array Into Three Subarrays
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
class Solution:
    def waysToSplit(self, nums: List[int]) -> int:
        mod = 10**9 + 7
        n = len(nums)
        prefix = [0] * (n + 1)
        for i in range(n):
            prefix[i + 1] = prefix[i] + nums[i]
        result = 0
        for i in range(1, n - 1):
            left = prefix[i]
            l = self.binary_search(prefix, i + 1, n - 1, left, True)
            r = self.binary_search(prefix, i + 1, n - 1, left, False)
            if l != -1 and r != -1 and l <= r:
                result = (result + r - l + 1) % mod
        return result

    def binary_search(self, prefix, start, end, left, find_left):
        res = -1
        while start <= end:
            mid = (start + end) // 2
            mid_sum = prefix[mid] - left
            right_sum = prefix[-1] - prefix[mid]
            if find_left:
                if mid_sum >= left:
                    res = mid
                    end = mid - 1
                else:
                    start = mid + 1
            else:
                if mid_sum <= right_sum:
                    res = mid
                    start = mid + 1
                else:
                    end = mid - 1
        return res

```
['Python3']