Finding longest equi-sum sequences :

Given two arrays A and B – of length N each.
In both these arrays, each element is either zero or one.
It is required to maximize (j – i) such that
ΣA[x] = ΣB[x], for i ≤ x ≤ j.
Develop a program which either finds the relevant values of i and j,
or reports that no such (i, j) exist.
Constraints :
(i) Size of array will be read from user, and memory will be allocated dynamically for the array.
(ii) The program will be menu-driven – there will be an option to either read the array elements from user, or to populate the array with random zeros/ones.
(iii) Worst case time complexity is O(N2) and worst case space complexity is O(N).