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?
- A. 5
- B. 4
- C. 3
- 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.
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
- Over all windows of size 3 in [4, 8, 2, 7, 5, 9], what is the smallest value of (window max minus window min)?
- How many index pairs i < j of length-2 substrings of "ababa" are equal strings?
- What is the smallest positive integer x such that floor(x/2) + floor(x/3) is at least 10?
- In [3, 8, 1, 8, 5], you move the rightmost occurrence of the maximum to the last position using adjacent swaps. How many adjacent swaps…
- How many unordered pairs of distinct words in ["abc", "aba", "cdc", "xyz", "axa", "cd"] share both the same first letter and the same last…
- How many index pairs i < j of [1, 2, 5, 7, 10] have absolute difference at least 3?