December 04, 2024 |17.6K Views

Partition Array Into Three Parts With Equal Sum

Explore Courseexplore course icon
Description
Discussion

To divide an array into three equal sum segments, first, check if the total sum is divisible by 3. If not, return [-1, -1]. Then, iterate through the array while maintaining a running sum. When the running sum equals one-third of the total, reset it to zero and store the index as the first segment. If another valid index is found, store it as the second segment and return the index pair. If no valid pair is found, return [-1, -1].

For more details, check out the full article: Split array into three equal sum segments.