3
int waysToPartition(vector<int> &nums, int k) {4
unordered_map<long long int, int> left;5
unordered_map<long long int, int> right;7
long long int sum = accumulate(nums.begin(), nums.end(), 0L);8
long long int leftSum = 0;11
for (int i = 0; i < n - 1; i++) {13
long long int rightSum = sum - leftSum;14
long long int difference = leftSum - rightSum;15
right[difference]++; // storing difference count in right, since no16
// difference exist in left19
int res = right[0]; // Point Zero difference are the partition points21
for (int i = 0; i < n; i++) {22
long long int D = k - nums[i];24
right[-D] + left[D]); // We can run a few test cases and see that if we25
// replace arr[i] by k, the difference D, the left side26
// including i,each element decreases by D while the27
// right Side each element increases by D, so we find -D28
// on right Side... WHY?? if right side is increasing by29
// D, we need to find -D since this will result in30
// -D+D=0, which are our partition points, since point 031
// signifies a partition where leftSum==rightSum,32
// similarly, left side decreases by D, so we find +D on33
// left since this will result in zero as well.36
long long int rightSum = sum - leftSum;37
left[leftSum - rightSum]++; // Now since we are moving our i forward, we38
// are gonna change the next i point, so we39
// are placing leftSum-RightSum on left side40
right[leftSum - rightSum]--; // From right we are gonna decrease it and41
// transfer to left side42
if (right[leftSum - rightSum] == 0) {43
right.erase(leftSum - rightSum);