Cant get it whats wrong with this code. I’m getting test cases wrong. Help.
Zero sum subarrays
Consider the case of 4 elements: 2, -2 , 3 , -3. Then, there are three subarrays whose sum is 0.
But ur code is showing output 2. Try to correct it.
I’ve tried fixing it. Still not getting it right. Check pls.
create a map which stores the frequency of each sum. Then add freq*(freq-1)/2 to the ans where freq is the frequency of a particular sum.
Cant it be done using sets ??
Can you give a test case for which this does not work ?
already given a testcase above.
I’ve fixed the code. Check again its working for the test case u provided
Consider the case when we are taking the prefix sum of the array and at 4 different points we have prefix sum equal to 1. Then according ur code the number of subarrays is 4 but it is wrong. The number of subarrays is 4C2.