Ans is option (iii).
Here we are having difference from -n to n so there are 2n+1 possibility of diff.
We are having 2 cases :
1: if index 0 to n is maxLength
2: any subarray having maxLength
For this we are maintaining a diff array and checking if sum in both array is equal then change maxLength.
public static int longestSpan(int arr,int n,int arr2)
int diff=new int[2*n+1];
//index finded by adding n as max neg val is -n
//from 0 to i