#1013
Easy Algorithms Partition array into three parts with equal sum
Array Greedy
42.6% acceptance
Feb 25, 2026
1790
169
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])
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn can_three_parts_equal_sum(arr: Vec<i32>) -> bool {
let total: i32 = arr.iter().sum();
if total % 3 != 0 { return false; }
let target = total / 3;
let mut parts = 0; let mut sum = 0;
for &x in &arr {
sum += x;
if sum == target * (parts + 1) { parts += 1; }
}
parts >= 3
}
}