Skip to content
LC-1013 Easy LeetCode

1013. Partition Array Into Three Parts With Equal Sum

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 42% Topics: Array, Greedy
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

class Solution(object):
    def canThreePartsEqualSum(self, A):
        """
        :type A: List[int]
        :rtype: bool
        """
        total = sum(A)
        if total % 3 != 0:
            return False
        parts, curr = 0, 0
        for x in A:
            curr += x
            if curr == total//3:
                parts += 1
                curr = 0
        return parts >= 3

Solution from kamyu104/LeetCode-Solutions · MIT