Spanning array

Given two binary arrays \(A\) and \(B\) (consisting of 1 and 0 only), a \(\text{span}(i,j)\) is defined for \(i\leq j\), where:

\[A[i]+A[i+1]+\cdots + A[j]=B[i]+B[i+1]+\cdots + B[j]\]

What is the length of the longest \(\text{span}(i,j)\) in the two arrays shown in the text file?

Details and Assumptions:

  • For \(A=[0, 1, 0, 0, 1]\) and \(B=[1, 0, 0, 1, 1]\), the longest span is of length 4: index 1 to 4. ( with \(0\) indexing)

  • For \(A=[0, 0, 0, 0, 0]\) and \(B=[1, 1, 1, 1, 1]\), the longest span is of length 0.

×

Problem Loading...

Note Loading...

Set Loading...