FAANG · LeetCode #525
Contiguous Array — three-stage drill
1The ProblemMedium
Contiguous Array
Longest contiguous subarray with an equal number of 0s and 1s.
Examples
[0,1,0,0,1,1,0]→ 6[1,1,1]→ 0
constraintOnly 0s and 1s.
2The PatternTIME O(n) · SPACE O(n)
Prefix Sum
Running cumulative totals turn range-sum questions into O(1) lookups.
Problems using this pattern
3The SolutionRESULT → 6
Step through it
start: seen = {0: -1} (balance 0 before the array), best = 0
Step 1 / 9
Arrow keys to navigate · escape to reset