Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the sum of the minimum value of every contiguous window of length 3 in the array [4, 2, 12, 11, -5, 3, 7]?
- A. -11
- B. -14
- C. 54
- D. -9
Correct answer: A. -11
Enumerate the five windows and take each minimum: 2, 2, -5, -5, -5. Summing the window maxima (12, 12, 12, 11, 7 = 54) is a classic mix-up.
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
- For each index i, let di be (index of the nearest element to the right that is strictly greater than a[i]) minus i, or 0 if no such…
- How many permutations of 1, 2, 3, 4, 5 can be sorted into increasing order by a single stack, where each input element is pushed in order…
- In the Josephus game, 41 people stand in a circle numbered 1 to 41. Starting from person 1, every 3rd person is removed (counting…
- What is the area of the largest rectangle that fits in a histogram whose bar heights are 2, 1, 5, 6, 2, 3 (each bar has width 1)?
- Rain falls on the elevation map [4, 2, 0, 3, 2, 5] (each bar has width 1). How many units of water are trapped in total?
- How many contiguous subarrays of [1, 2, 1, 2, 3, 3, 4] contain at most 2 distinct values?