Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: In the binary string "0011100", what is the length of the longest contiguous substring that contains equal numbers of 0s and 1s?
- A. 6
- B. 4
- C. 7
- D. 2
Correct answer: A. 6
Prefix balances (+1 for 1, −1 for 0) repeat 6 apart, e.g. "001110" with three of each, so 6. "0011" gives 4, the whole string (7) has four 0s and three 1s, and 2 is a single "01".
More Coding Interview Problems questions
- Problem: How many strings of length 3 over the alphabet {a, b, c} contain no two consecutive a's?
- Problem: The number of subsets of {1, 2, 3, 4} whose elements sum to exactly 5 (the empty set is excluded) is what value?
- Problem: The number of ways to make 15 using coins of values 2, 3 and 5, where the order of coins does not matter, is what value?
- Problem: The sum of the numbers obtained by repeatedly removing the first and last elements of [1, 2, 3, 4, 5, 6, 7, 8] and adding them as…
- Problem: What is the remainder when 2^100 is divided by 9?
- Problem: The sum of all three-digit palindromic numbers (100–999) is what value?