Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the sum of (max minus min) over all windows of size 3 in [2, 7, 1, 8, 2]?
- A. 21
- B. 24
- C. 17
- D. 20
Correct answer: D. 20
Each window of size 3 contributes its spread: windows [2,7,1] gives 6, [7,1,8] gives 7, [1,8,2] gives 7, totalling 20. Sliding deques give the same result in linear time.
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 smallest positive integer x such that the sum of floor(x / ai) over a = [2, 3, 5] is at least 20?
- What is the lexicographically smallest subsequence of length 3 of "cbacdcbc"?
- How many positive divisors of 2^5 3^2 7 are odd?
- How many non-empty contiguous subarrays of [3, 3, 1, 2, 2, 1] have bitwise XOR equal to 0?
- How many distinct palindromic substrings (as strings, not positions) does "aaaa" have?
- A road of length 24 has fuel stations at kilometres 3, 7, 9, 14, 17, 22. The car starts at 0 and has range 8 km per tank (it refuels fully…