Can anyone figure out what i have done wrong?
  1. Partition Array Into Three Parts With Equal Sum

i have used the two pointer technique

class Solution {
public:
bool canThreePartsEqualSum(vector& arr) {
int n = arr.size();
int p1 = 0,p2 = n-1,total = 0,sum1 = arr[0],sum2 = arr[n-1];
for(int i=0;i<n;i++)total+=arr[i];
while(p1<p2)
{
if(sum1<sum2)
{p1++;sum1+=arr[p1];}
else if(sum1>sum2)
{p2--;sum2+=arr[p2];}
else
{
if((total-(sum1+sum2)) == sum2)
return true;
}
}
return false;
}
};

Comments (0)