In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems. A permutation p of size n is given. A permutation of size n is an array of size ...
A deque (short for double-ended queue) is a linear data structure that allows adding and removing elements from both ends. It supports fast and memory-efficient operations such as append, pop, ...
This needs a deque because the algorithm evicts at both ends, at the front when an index leaves the window, at the back when a newly arriving value dominates the tail. A stack cannot evict the front ...
Friday Learning Series - one practical technical concept each week. We usually reach for familiar tools. PriorityQueue when we need min/max tracking, or TreeMap when we want sorted order with fast ...