Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
From the windows of length 3 of [3, 9, 2, 8, 1, 7], remove the smallest element of the chosen window and maximise the sum that remains. What is the largest remaining sum?
- A. 18
- B. 15
- C. 17
- D. 14
Correct answer: C. 17
Within each window the best removal is its minimum, so the answer is the maximum over windows of (window sum minus window minimum). Removing the largest element is the opposite greedy and is wrong.
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 sum of (max minus min) over all windows of size 3 in [2, 7, 1, 8, 2]?
- 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?