Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
In the binary string "1101001100", find the length of the longest substring that has equally many 0s and 1s and whose length is a multiple of 4.
- A. 12
- B. 8
- C. 6
- D. 9
Correct answer: B. 8
Balanced substrings are pairs of equal prefix balances; the extra condition that the length is a multiple of 4 is checked by requiring the two prefix indices to agree mod 4. Ignoring that condition gives a longer, invalid answer.
More Coding Interview Problems questions
- Values [1, 9, 4, 12, 7, 15, 3]. How many unordered pairs of distinct positions have an absolute difference of at least 5?
- How many subsets of {1, 2, ..., 12} have a sum of exactly 20?
- How many integers x with 1 <= x <= 200 have an odd number of 1-bits in their binary representation?
- Meetings (closed-open as half-open intervals) are [1,4), [1,4), [2,6), [5,8), [3,9), [7,10). A room can be reused the moment a meeting…
- Closed integer intervals [1,3], [2,5], [4,7], [6,9], [8,10], [5,6] are available. What is the minimum number needed so that every integer…
- Array [3, 1, 2, 5, 0, 4, 2]. How many contiguous subarrays have a sum equal to twice their length?