1712. Ways to Split Array Into Three Subarrays

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1712

class Solution:
    def waysToSplit(self, nums: List[int]) -> int:
        mod = 10**9 + 7
        s = list(accumulate(nums))
        res, n = 0, len(nums)
        for i in range(n - 2):
            j = bisect_left(s, s[i] << 1, i + 1, n - 1)
            k = bisect_right(s, (s[-1] + s[i]) >> 1, j, n - 1)
            res += k - j
        return res % mod