In the function written for the longest subbarray I do not think there should be an else loop present while storing the values. In the previous question(length of longest subarray with sum =0) we had two points in the cumulative sum array with the same value therefore we needed an else loop to store the first index while such is not the case here.
I have attached an image of my function below:
Could you please tell me am I right or wrong??