Zepruv › Coding problems

Partition Array Into Three Parts With Equal Sum

Easy · Array, Greedy

Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.length - 1])

Example 1

Input: arr = [0,2,1,-6,6,-7,9,1,2,0,1]
Output: true

0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1

Example 2

Input: arr = [0,2,1,-6,6,7,9,-1,2,0,1]
Output: false

Example 3

Input: arr = [3,3,6,5,-2,2,5,1,-9,4]
Output: true

3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4

Constraints

Starter code (python)

class Solution(object):
    def canThreePartsEqualSum(self, arr):
        """
        :type arr: List[int]
        :rtype: bool
        """
        

Related problems

Previous: Capacity To Ship Packages Within D Days · Next: Best Sightseeing Pair · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.