24. Longest Span in two Binary Arrays
β GFG solution to Longest Span in two Binary Arrays: find longest span with equal sums using prefix difference and hash map technique. π
π§© Problem Description
π Examples
Example 1
Input: a1[] = [0, 1, 0, 0, 0, 0], a2[] = [1, 0, 1, 0, 0, 1]
Output: 4
Explanation: The longest span with same sum is from index 1 to 4 (0-based indexing).
Sum in a1[1:4] = 1+0+0+0 = 1, Sum in a2[1:4] = 0+1+0+0 = 1Example 2
Input: a1[] = [0, 1, 0, 1, 1, 1, 1], a2[] = [1, 1, 1, 1, 1, 0, 1]
Output: 6
Explanation: The longest span with same sum is from index 1 to 6 (0-based indexing).Example 3
π Constraints
β
My Approach
Prefix Difference Technique
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated