Data Structures & AlgorithmsModerateTCS NQT · Infosys

In the binary array [1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1] you may flip at most ONE 0 to a 1. What is the length of the longest run of consecutive 1s you can obtain?

  1. A. 3
  2. B. 5
  3. C. 6
  4. D. 8

Correct answer: C. 6

Keep, for each right end, the longest window containing at most one zero; that window length is the best run after the flip. The current run without flipping or counting all ones both miss the bridge across a zero.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic