Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
For the binary array [1, 0, 1, 1, 0, 1, 1, 1, 0, 1], you may flip at most 2 zeros to ones. What is the length of the longest run of ones you can obtain?
- A. 7
- B. 3
- C. 5
- D. 8
Correct answer: D. 8
A window with at most two zeros: indices 2–9 (1 1 0 1 1 1 0 1) has length 8. Counting all the ones gives 7, the longest run with no flips is 3, and adding k = 2 to that run gives 5, missing that flips join runs.
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 distinct strings appear among the rotations of "abab" (all n cyclic shifts, including the unshifted string)?
- What is the length of the longest substring of "aaabbbcaabbbcc" in which every letter occurring in it appears at least 3 times?
- How many contiguous subarrays of [1, 2, 3, 3, 2, 1, 4] have a bitwise XOR of exactly 0?
- Among pairs of distinct elements of [-8, -3, 1, 5, 9, 12], which pair sum is closest to the target 4? (Report the sum itself.)
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 1, 4, 2]?
- What is the area of the largest rectangle containing only 1s in the binary matrix whose rows are 1101, 1111, 0111 and 1110?