The Contiguous Array interview question gives you a binary array (containing only 0s and 1s). You need to find the maximum length of a contiguous subarray that contains an equal number of 0s and 1s.
Companies like Meta, Amazon, and Adobe use the Contiguous Array coding problem to test a candidate's ability to use the Prefix Sum technique creatively. It requires a mathematical transformation of the input to reveal a simpler sub-problem.
This problem follows the Array, Hash Table, Prefix Sum interview pattern.
Array: [0, 1, 0, 0, 1, 1] Transform: [-1, 1, -1, -1, 1, 1]
The trick of "treating 0 as -1" is a classic pattern for balancing problems. Whenever you need to find "equal counts" of two items, mapping them to 1 and -1 and using prefix sums is often the most optimal path.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Subarray Sums Divisible by K | Medium | Solve | |
| Count of Interesting Subarrays | Medium | Solve | |
| Maximum Size Subarray Sum Equals k | Medium | Solve | |
| Subarray Sum Equals K | Medium | Solve | |
| Make Sum Divisible by P | Medium | Solve |