Module 4 · array and deque: Fixed Size, and Growing at Both Ends
CP and Interview Pack: array and deque Patterns, Questions and the Bug Gallery
ProReading
Codeforces Round 569 opened its Div. 1 set with problem 1179A, "Valeriy and Deque" (1180C in Div. 2). A deque holds n numbers. One operation takes the first two, A and B, and puts the larger back at the front and the smaller at the back. Each query asks which pair the m-th operation takes, and m can be far larger than any loop can reach. Bob simulates every step; Amara simulates only n - 1, and her whole solution is pattern 1 below.
Checking what this lesson needs for you…
What is inside CP and Interview Pack: array and deque Patterns, Questions and the Bug Gallery
- Pattern 1: a queue simulation
- Pattern 2: a circular buffer on an array
- Pattern 3: rotation, and the k % n shortcut
- Pattern 4: both-ends greedy
- Pattern 5: the reverse flag
- Two deque patterns that later modules finish
- Eight interview questions, with model answers