Help needed regarding interview question to find all possible subranges
Anonymous User
283

I recently got this question in an interview and wasn't able to figure out a good approach.

Problem:
Given two arrays A and B containing N elements each.
We can pick a range [L , R] where 1 <= L <= R <= N,
Such that for each index i, L <= i <= R,
we can either take ith element from A or B, but we must ensure that sum of elements taken from A equals sum of elements taken from B within the range.

We need to find the number of possible unique ways to choose ranges [L, R] such that this condition is satisfied.
Note: Two ranges are different if L or R are different or if in one, ith element is taken from A and in other from B.

Return the answer modulo 1e9+7.
N <= 10000
Sum of elements of A <= 10000
Sum of elements of B <= 10000

I was trying some DP approaches but ultimately am unable to think up a correct solution. Any ideas ?

Comments (4)