Data Structures & AlgorithmsHardGATE CS · TCS NQT

For [1, 0, 1, 1, 0, 1, 0, 1], consider windows of length 4. In each window you may flip at most one 0 to 1. What is the largest number of 1s you can obtain in a single window?

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

Correct answer: B. 4

The window at indices 2 to 5 (1, 1, 0, 1) has one zero that can be flipped, giving four ones, the largest possible for a window of length 4.

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

Exams that ask this topic