Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 C
Problem: In the binary string "1101001110100110", what is the length of the longest contiguous substring containing equal numbers of 0s and 1s?
- A. 6
- B. 35
- C. 14
- D. 16
Correct answer: C. 14
Map 1 → +1 and 0 → −1 and keep the FIRST index of each prefix balance (seeded with 0 at −1); the largest gap is 14. Overwriting with the latest index gives 6, counting balanced substrings gives 35, and 16 assumes the whole string is balanced although it has 9 ones and 7 zeros.
More Coding Interview Problems questions
- Problem: For the string "abcab", count the subsequences of length 3 that are palindromes (choose 3 indices i < j < k with s[i] = s[k]; the…
- Problem: What is the minimum number of characters that must be inserted anywhere in "leetcode" to make it a palindrome?
- Problem: What is the length of the longest valid (well-formed) parentheses substring of ")()())(()" ?
- Problem: How many strings of length 8 made of matched parentheses ( and ) are valid (well-formed)?
- Problem: A robot is on a 4×4 torus (moving off one edge reappears on the opposite edge) starting at (0,0), using row, column coordinates…
- Problem: Evaluate the postfix expression "3 4 + 2 7 −" using a stack (the operator pops the top two values, computes second-from-top op…