Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
Which structure returns the maximum of every window of size k in a sliding pass in O(n) total time?
- A. Binary heap of all window elements
- B. Sorted array with insertion
- C. Monotonic deque
- D. Hash map of window counts
Correct answer: C. Monotonic deque
A deque keeps indices in decreasing value order; the front is the window maximum and each index enters and leaves at most once.
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
- To test whether string s2 is a rotation of string s1 in linear time, which approach is standard?
- For each element of an array of distinct integers, the task is to count how many earlier elements are smaller. Which structure achieves…
- What is the length of the longest common subsequence of the three strings "ABCBDAB", "BDCABA" and "BCADB"?
- How many non-empty subsequences of "abcbab" (chosen by index, so the same letters at different positions count as different subsequences)…
- How many index triples i < j < k in [3, 1, 4, 1, 5, 9, 2, 6] satisfy a[i] < a[j] < a[k] (strictly increasing)?
- You stand on index 0 and must reach index 7. From index i you may move to any of the next 2 indices (i+1 or i+2). Landing on index j costs…