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 &lt; 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])

&nbsp;
Example 1:

Input: arr = [0,2,1,-6,6,-7,9,1,2,0,1]
Output: true
Explanation: 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
Explanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4


&nbsp;
Constraints:


	3 &lt;= arr.length &lt;= 5 * 104
	-104 &lt;= arr[i] &lt;= 104


class Solution:
    def canThreePartsEqualSum(self, arr: List[int]) -> bool:
        total = sum(arr)
        if total % 3 != 0:
            return False
        ave = total // 3
        stage = 0
        add = 0
        for i in arr[:-1]:
            add += i
            if add == ave:
                stage +=1
                add = 0
            if stage == 2:
                return True
        return False
class Solution { 
     public boolean canThreePartsEqualSum(int[] arr) {
        int sum = 0;
        
        for (Integer no : arr) {
            sum += no;
        }
        if (sum % 3 != 0) {
            return false;
        }
        sum = sum / 3;
        int tempSum = 0;
        int count = 0;

        for (int i = 0; i < arr.length; i++) {
            tempSum += arr[i];
            if (tempSum == sum) {
                count++;
                tempSum = 0;
            }
        }

        return count >= 3;
    }
}
class Solution {
public:
	bool canThreePartsEqualSum(vector<int>& arr) {
		int sum=0;
		for(auto i : arr)
			sum+=i;
		if(sum%3!=0)
			return false;   //partition not possible
		int part=sum/3,temp=0,found=0;
		for(int i=0;i<arr.size();i++){
			temp+=arr[i];
			if(temp==part){
				temp=0;
				found++;
			}
		}
		return found>=3 ? true : false;
	}
};

feel free to ask your doubts :)
and pls upvote if it was helpful :)
var canThreePartsEqualSum = function(arr) {
    const length = arr.length;
    let sum =0, count = 0, partSum = 0;
    for(let index = 0; index < length; index++) {
        sum += arr[index];
    }
    if(sum%3 !== 0) return false;
    partSum = sum/3;
    sum = 0;
    for(let index = 0; index < length; index++) {
        sum += arr[index];
        if(sum === partSum){
            count++;
            sum = 0;
            if(count == 2 && index < length-1) return true;
        }
    }
    return false;
};
Partition Array Into Three Parts With Equal Sum