07. Longest Span in two Binary Arrays
β GFG solution to find the longest span where two binary arrays have equal sum in the span. π
π§© 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.
Example 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.
π Constraints
β
My Approach
Prefix Sum and Hash Map of Differences
π‘ Idea:
βοΈ Algorithm Steps:
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
π§βπ» Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated