Monotonic Queue MCQ Set for SDE Interview Prep

Q1. In sliding-window maximum, why is the deque-based solution $O(n)$ instead of $O(n \times k)$?




Q2. While pushing a new element in a max-monotonic queue, you pop all smaller elements from the back. What is the purpose of this?




Q3. How can you adapt a monotonic-queue solution for sliding-window *minimum* instead of maximum?




Q4. If the window size $k$ is 1 or larger than the array length $n$, what will the sliding-window maximum output be?




Q5. A common mistake is not removing indices that fall out of the window. What happens if you never pop the front when it’s out of range?




Q6. Some implementations pop not only smaller but also equal values when inserting a new element. Why pop an equal value for a max-monotonic queue?




Q7. In a streaming analytics system, you need the maximum of the last $k$ readings at any time. What data structure handles this most efficiently?




Q8. Why does the 0–1 BFS algorithm (for graphs with edge weights 0 or 1) use a deque instead of a priority queue like Dijkstra’s?




Q9. What is an advantage of the deque-based approach over a segment tree for sliding-window maximum in terms of memory?




Q10. Using a max-heap or balanced BST (multiset) for sliding-window maximum leads to what complexity, compared to using a monotonic deque?




Q11. In a “jump game” where $dp[i] = \text{nums}[i] + \max(dp[i-1 \dots i-k])$, how can we compute this efficiently for large $n$?




Q12. There’s a trick to get a queue with “max” in constant time by using two stacks (one for incoming, one for outgoing), each tracking their max. What is the time complexity per operation for this two-stack queue?




Q13. Suppose you accidentally use the wrong comparison when maintaining the deque (e.g., `<` instead of `>` in a max-queue). What would be the outcome?




Q14. Why do most sliding-window maximum implementations store *indices* in the deque instead of the actual values?




Q15. The “Constrained Subsequence Sum” problem (max sum of a subsequence with adjacent elements at most $k$ apart) can be solved by DP with a deque. How does the deque help?




data-structures-and-algorithms monotonic-queues