Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B
What is the largest sum of any contiguous window of exactly 4 elements of [2, 7, 1, 8, 2, 8, 1, 8, 2, 8]?
- A. 19
- B. 18
- C. 23
- D. 11
Correct answer: A. 19
A fixed-size sliding window updates the sum by adding the entering element and removing the leaving one, giving O(n). Taking the four largest values overall ignores that they must be contiguous.
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 non-empty subsets of [3, 5, 6, 7, 9] (chosen by position) have a sum divisible by 4?
- A row of 100 lights starts off. For each i from 1 to 100, the lights at positions that are multiples of i are toggled. How many lights are…
- The array [1, 9, 4, 6, 2, 8] has even length. You pair up the elements (each element in exactly one pair), and the cost of the arrangement…
- How many contiguous subarrays of [2, 5, 1, 5, 3, 4, 5] have a maximum element exactly equal to 5?
- In [3, 8, 1, 6, 9, 4], find the pair of distinct indices (i < j) with a[i] + a[j] = 10, minimising i + j. What is the minimum value of i +…
- How many DISTINCT sums appear among the windows of exactly 3 consecutive elements of [4, 1, 4, 2, 1, 4, 2]?