Partition Array Into Three Parts With Equal Sum (Leetcode 1013)

Problem Link: https://leetcode.com/problems/partition-array-into-three-parts-with-equal-sum/

class Solution:
    def canThreePartsEqualSum(self, arr: List[int]) -> bool:
        
        s=sum(arr)
        if(s%3!=0):
            return False
        s=s//3
        tempsum=0
        cnt=0
        n=len(arr)
        for i in range(n):
            tempsum=tempsum+arr[i]
            if(tempsum==s):
                tempsum=0
                cnt+=1
        if(cnt>=3):
            return True
        else:
            return False   

Last updated