Algorithms and Data Structures · Middle · Question 23 of 75

Which structure gives O(1) insertion and removal at both ends?

Explanation

A deque is usually a ring buffer or a doubly linked list. It's the key structure for "sliding window maximum" in O(n): it keeps candidate indices in decreasing order of value.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 23

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz