Back to photostream

Partition Array Into Three Parts With Equal Sum Leetcode Solution

The problem Partition Array Into Three Parts With Equal Sum Leetcode Solution provides us with an array or vector and asks if there are three partitions possible of the sequence. Here, by partition we mean that is there two indices i, j such that the sum of elements from start to ith index is equal to the sum of elements from i+1 to jth index. And the sum of elements from j+1 index to the last element is also equal to the first two segments of the array. If there exist such two indices, we say the array can be partitioned into three parts with an equal sum, else no. Before moving into the solution let's see a few examples.

 

arr =

true

Explanation: Since we can divide the array into three segments of the equal sum. Thus we can say that the array can be partitioned into three equal sums. More formally, 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1.

arr =

false

Explanation: Since there is no way to divide the array into three separate sections that have the same sums. Thus the answer is false.

Approach for Partition Array Into Three Parts With Equal Sum Leetcode Solution

The problem Partition Array Into Three Parts With Equal Sum Leetcode Solution asked us if we can partition the given array into three disjoint subarrays that have equal sums. So, to solve the problem first we need to find the total sum of the array. If the total sum is not divisible by 3, then the answer is false. Because then there is no way to divide the array into three equal sub-parts.

 

www.tutorialcup.com/leetcode-solutions/partition-array-in...

8 views
0 faves
0 comments
Uploaded on September 7, 2021