At 8:25, Is the rightSum = totalSum - a[i] - leftSum ?
@PlacementsReady Жыл бұрын
Yes please go through full video u will get it
@BhavanaBharatiSingh5 ай бұрын
@@PlacementsReady but it wont work it we have first position as equilibrium point for e.g: 1,0 so we need to use rightsum = totalsum - a[i], leftsum += a[i] and consdition to return is if leftsum == rightsum-a[i]
@riyasingh6864 Жыл бұрын
Very good explaination
@PlacementsReady Жыл бұрын
Thanks Riya. Glad that you liked it.
@farhanmuhamed392 Жыл бұрын
Two pointer method is more optimised, only takes O(n) time instead of O(2n)
@cosmosXverse Жыл бұрын
can you explain little bit...about two pointer method
@PlacementsReady Жыл бұрын
@farhanmuhamed392 how are you solving this question using two pointer approach?
@farhanmuhamed392 Жыл бұрын
@@PlacementsReady int equilibriumPoint(long long a[], int n) { int left=0, right=n-1; long long sumLeft=a[left], sumRight=a[right]; while(left != right){ if(sumLeft > sumRight){ right--; sumRight = sumRight + a[right]; } else{ left++; sumLeft = sumLeft + a[left]; } } if( sumLeft == sumRight) return left+1; else return -1; }
@farhanmuhamed392 Жыл бұрын
@@cosmosXverse Declare 4 variables left, right, leftSum, rightSum left and right are pointers , and leftSum and rightSum keep track sum of value at current pointers int equilibriumPoint(long long a[], int n) { int left=0, right=n-1; long long sumLeft=a[left], sumRight=a[right]; while(left != right){ if(sumLeft > sumRight){ right--; sumRight = sumRight + a[right]; } else{ left++; sumLeft = sumLeft + a[left]; } } if( sumLeft == sumRight) return left+1; else return -1; }
@pranavmittal2976 Жыл бұрын
@@farhanmuhamed392 bro it is failing for the test case 1 2 0 3 it expected output is 3 but it is printing -1