Data Structures & AlgorithmsHardGATE CS · TCS NQT
What is the length of the longest contiguous substring of the binary string 1100101101 that contains equal numbers of 0s and 1s?
- A. 6
- B. 10
- C. 8
- D. 12
Correct answer: C. 8
Map each 0 to -1 and each 1 to +1; a balanced substring is a pair of equal prefix sums, and the longest one is the maximum gap between first and last occurrence.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index pairs i < j make a[i] times a[j] a perfect square, for the array [2, 8, 18, 5, 12, 9, 50, 25, 32]?
- Keys 10, 22, 31, 4, 15, 28, 17, 88, 59 are inserted in this order into an open-addressing table of size 11 with h(k) = k mod 11 and linear…
- A table of size 11 uses double hashing with h1(k) = k mod 11 and h2(k) = 1 + (k mod 9), probe position (h1 + ih2) mod 11. Keys 5, 16, 27…
- What is the value of the prefix-function (KMP failure function) at the last position of the string aabaaab?
- What is the sum of the Z-function values Z[i] for i = 1 to n-1 of the string aaabaaab (Z[i] is the length of the longest common prefix of…
- How many palindromic substrings (counted by position, so repeated letters at different positions count separately) does the string…