Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT
Choose two NON-OVERLAPPING contiguous windows of [5, -2, 8, 1, -3, 6, 2, 4]: one of length exactly 2 and one of length exactly 3. What is the maximum total of their sums?
- A. 17
- B. 23
- C. 22
- D. 21
Correct answer: D. 21
Compute window sums of both lengths, then for every cut position combine the best window on one side with the best window of the other length on the other side using prefix and suffix maxima. Taking the two best windows independently can make them overlap.
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 pairs of positions (i, j) with j − i ≥ 3 satisfy a[i] = a[j], for the array [1, 2, 1, 3, 2, 1, 3, 1]?
- How many non-empty contiguous subarrays of [2, 2, 5, -1, 3, 4, 1] have a sum that is a perfect square (0 counts as a square)?
- How many non-empty subsets of [3, 1, 4, 2, 5] (chosen by position) have a sum between 4 and 7 inclusive?
- Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the…
- How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index…
- Deleting exactly one character from "110100" gives a new binary string each time. How many DISTINCT strings result?