[Python] Clear Prefix Sum+Binary Search Solution with Video Explanation
Video with clear visualization and explanation:\nhttps://youtu.be/tSYfTRau5HE\n\nIntuition: Prefix Sum+Binary Search\n\nCode\n\nInspired by https://leetcode.com
Video with clear visualization and explanation:\nhttps://youtu.be/tSYfTRau5HE\n\nIntuition: Prefix Sum+Binary Search\n\n**Code**\n\nInspired by https://leetcode.com/problems/ways-to-split-array-into-three-subarrays/discuss/999157/Python3-binary-search-and-2-pointer\n\n```\nfrom bisect import *\n\nclass Solution:\n    def waysToSplit(self, nums: List[int]) -> int:\n        mod = 10**9+7\n        \n        pre_sum = [0]\n        for num in nums: \n            pre_sum.append(pre_sum[-1]+num)\n        \n        res = 0\n        \n        for i in range(1, len(nums)): \n            l = bisect_left(pre_sum, 2*pre_sum[i])\n            r = bisect_right(pre_sum, (pre_sum[i]+pre_sum[-1])//2)\n            res += max(0, min(len(nums), r)-max(i+1, l))\n            \n        return res%mod\n```\n\nTime: O(nlogn) / Space: O(n)\n\nFeel free to subscribe to my channel. More LeetCoding videos coming up!
['Python']