Three Equal Parts || Easy C++ Solution
\tclass Solution {\n\tpublic:\n    vector threeEqualParts(vector& A) {\n        //count number of 1\'s\n        int totalOnes=accumulate(A.begin(), A.end(), 0);
\tclass Solution {\n\tpublic:\n    vector<int> threeEqualParts(vector<int>& A) {\n        //count number of 1\'s\n        int totalOnes=accumulate(A.begin(), A.end(), 0);\n        //if we can not divide into 3 parts then return -1,-1\n        if(totalOnes%3!=0){\n            return {-1,-1};\n        }\n      \n        int result=totalOnes/3, size=A.size();\n        //if sum is zero\n        if(result==0){\n            return {0, size-1};\n        }\n        \n        int tempSum=0,i1=-1,i2=-1,i3=-1,j1=-1,j2=-1,j3=-1;\n        for(int i=0;i<size;i++){\n            if(A[i]){\n                //count number of 1\'s have occured\n                tempSum++;\n                //for first 1, initialise the start index of first half\n                if(tempSum==1) i1=i;\n                //if first half is completed, then initialise the end index of first half\n                if(tempSum==result) j1=i;\n                //if second half is started, then initialise the start index of second half\n                if(tempSum==result+1) i2=i;\n                //if second half is completed, then initiliase the end index of second half\n                if(tempSum==2*result) j2=i;\n                //if third half is started, then initialise the start index of third half\n                if(tempSum==2*result+1) i3=i;\n                //if third half is completed, then initiliase the end index of third half and break as no need iterator further\n                if(tempSum==3*result) { j3=i; break; }\n            }\n        }\n        //verify all three parts are same, if not then they will not generate the same number eg. 101 and 1001 both contains same number of 1\'s but they are not same\n        vector<int> firstHalf(A.begin()+i1, A.begin()+j1);\n        vector<int> secondHalf(A.begin()+i2, A.begin()+j2);\n        vector<int> thirdHalf(A.begin()+i3, A.begin()+j3);\n        \n        if(firstHalf!=secondHalf or secondHalf!=thirdHalf){\n            return {-1,-1};\n        }\n        \n        //now consider the 0\'s between first half and second half or second half and third half or after third half\n        int firstZero=i2-j1-1;\n        int secondZero=i3-j2-1;\n        int thirdZero=A.size()-j3-1;\n        //if 0\'s after third half are more than first and second then they will increase the number produced in third Half and the above verification will fail\n        //if 0\'s after third half are less than first and second then the extra 0s in first and second will adjust at start of second half and third half and they will not hamper the above verification\n        if(thirdZero>firstZero or thirdZero>secondZero){\n            return {-1,-1};\n\t\t\t}\n        //add those 0\'s found after third at end of firstHalf and secondHalf to make all 3 halfs symmetric\n        return {j1+thirdZero, j2+thirdZero+1};\n\t\t}\n\t};
[]