The Deque is a double ended queue which comes in handy when we are working with continuous ranges. The problem solved here is finding all maximum elements in ranges of size R for a given array.
The brute force approach takes O(N^2) time to find the largest amongst all segments of size R. A heap does much better, taking O(N*logR) time.
The best solution uses a Deque data structure to bring down the complexity to O(N). This is possible because we keep track of which elements should be compared with the one being currently inserted.
Problem statement with solution:
www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
Practice Problems:
https://www.codechef.com/MAY15/proble...
https://www.codechef.com/FEB17/proble...
https://www.codechef.com/JUNE16/probl...
On this page of the site you can watch the video online Deque - Data Structure with a duration of hours minute second in good quality, which was uploaded by the user Gaurav Sen 12 March 2017, share the link with friends and acquaintances, this video has already been watched 60,718 times on youtube and it was liked by 715 viewers. Enjoy your viewing!