Can u explain why we are using map in this case?
Usage of map doubt
hello @vatsal50
we want to store the prefix sum along with the index at which that particular sum occured thats why we are using map.
map[key]=value
key is prefix sum
value is the index at which the prefix sum occured.
using this map we can easy find the subarray with sum 0.
how?
let say prefsum is occured at index i and again occured at index j.
then this means subarray between [i+1…j] has sum zero becuase then ony it is possible to get the same prefsum back
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.