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?
- A. 3
- B. 5
- C. 6
- 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.
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
- What is the length of the longest STRICTLY increasing subsequence of [3, 10, 2, 1, 20, 4, 6, 7, 6, 7, 8, 2]?
- For the array [1, 3, 5, 4, 7, 2, 2, 8, 6, 9], how many DIFFERENT subsequences (chosen by index) are strictly increasing AND have the…
- What is the maximum possible SUM of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5]?
- The longest bitonic subsequence of an array is a subsequence that first strictly increases and then strictly decreases (either part may be…
- A pair (a, b) can follow pair (c, d) in a chain when b < c. The pairs are [(5, 24), (39, 60), (15, 28), (27, 40), (50, 90), (1, 2), (3…
- What is the minimum number of elements you must DELETE from [9, 4, 7, 2, 10, 3, 8, 11, 5] (the rest keep their order) so that the…