📌📌 Well-Coded || Both Method || Two-Pointer || Binary Search 🐍
IDEA:\n\nTwo Pointers :\n\'\'\'\n\n\tclass Solution:\n    def waysToSplit(self, nums: List[int]) -> int:\n        \n        MOD = 109 + 7\n        n = len(nums)
## IDEA:\n\n**Two Pointers :**\n\'\'\'\n\n\tclass Solution:\n    def waysToSplit(self, nums: List[int]) -> int:\n        \n        MOD = 10**9 + 7\n        n = len(nums)\n        for i in range(1,n):\n            nums[i]+=nums[i-1]\n        \n        res,j,k = 0,0,0\n        for i in range(n-2):\n            if j<=i:\n                j = i+1\n            while j<n-1 and nums[i]>nums[j]-nums[i]:\n                j+=1\n            \n\t\t\tif k<j:\n                k = j\n            while k<n-1 and nums[k]-nums[i]<=nums[n-1]-nums[k]:\n                k += 1\n            res = (res + k - j)%MOD\n        \n        return res\n\n****\n**Using Binary Search :**\n\'\'\'\n\n\tclass Solution:\n    def waysToSplit(self, nums: List[int]) -> int:\n        mod, pre_sum = int(1e9+7), [nums[0]]\n        for num in nums[1:]:                               # create prefix sum array\n            pre_sum.append(pre_sum[-1] + num)\n        ans, n = 0, len(nums)\n        for i in range(n):                                 # pre_sum[i] is the sum of the 1st segment\n            prev = pre_sum[i]                              # i+1 is the starting index of the 2nd segment\n            if prev * 3 > pre_sum[-1]: break               # break loop if first segment is larger than the sum of 2 & 3 segments\n                \n            j = bisect.bisect_left(pre_sum, prev * 2, i+1) # j is the first possible ending index of 2nd segment\n                \n            middle = (prev + pre_sum[-1]) // 2             # last possible ending value of 2nd segment\n            k = bisect.bisect_right(pre_sum, middle, j+1)  # k-1 is the last possible ending index of 2nd segment\n            if k-1 >= n or pre_sum[k-1] > middle: continue # make sure the value satisfy the condition since we are using bisect_right here\n            ans = (ans + min(k, n - 1) - j) % mod          # count & handle edge case\n        return ans\n\n### Thanks and Upvote if you got any help!!\uD83E\uDD1E
['Binary Tree', 'Python', 'Python3']