Data Structures & AlgorithmsHardGATE CS · ICPC regional
A sliding window of size 3 moves over the array [5, 1, 4, 2, 8, 7, 6]. For each window take its maximum and then take the minimum of those maxima. What is the result?
- A. 5
- B. {C+7}
- C. 7
- D. 4
Correct answer: D. 4
The window maxima are 5, 4, 8, 8, 8; the minimum of these is 4. A monotonic deque produces the maxima in O(n).
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 number of distinct values of a[i] XOR a[j] over all pairs i < j of the array [1, 2, 3, 4]?
- How many palindromic substrings does the string aabbaa contain (counted by position)?
- What is the number of distinct subsequences (including the empty one) of the string abab?
- Starting at value 1, apply the operations x -> 2x, then x -> x + 3, alternating (double, add 3, double, add 3, ...), for 6 operations in…
- A matrix has rows [1, 2, 3], [4, 5, 6], [7, 8, 9]. The matrix is transposed and then each row is reversed. What is the element in row 0…
- How many subsequences of length 3 of the string abcabc are palindromes (distinct index choices count separately)?