Subsets Summing Zero

a method findSumZeroSubsets to return the starting and ending indexes of all subarrays in it that sum up to zero?

Note :
There are 3 terms that you should be able to distinguish when in the context of arrays. Those are:

  1. Subset: A subset of an array is what it says exactly, a piece of a larger set. It is not ordered and not contiguous. Bear in mind that there can be empty subsets of an array.
  2. Subsequence: A subsequence is a non-empty subset that maintains the order of the elements according to the original array.
  3. Subarray: A non-empty subset of an array that is contiguous.

image

 arr = [3, 5, -2, -4, 7, -1, 6, 8, -8, 4]
findSumZeroSubsets(arr);
// [[2, 5], [7, 8]]
// From 2 to 5
// From 7 to 8

arr = [4, -5, 1, -3, 2, -8, 5, -2, 9]
findSumZeroSubsets(arr);
// [[0, 2], [2, 4]]
// From 0 to 2
// From 2 to 4

can anyone help me to get the indcies of the subset sum, i have computed the count of the subset summig to zero but not able to get the start Index and end Index of that subarray. it ould be very helpful if anyone can helpl me to get those indices.

Comments (2)