Module 5 · list and forward_list: When Elements Move and Positions Must Not
CP and Interview Pack: list Patterns, Questions and the Bug Gallery
ProReading
Codeforces Round 552 (Div. 3) has problem 1154E, "Two Teams". n students stand in a row, each with a different skill from 1 to n. Two coaches take turns. Each picks the most skilled student left, plus up to k nearest students on each side, and they leave the row. Bob rescans the row for every pick and runs out of time. Amara keeps the row in a list with an iterator to every student, and her whole solution is the first program below.
Checking what this lesson needs for you…
What is inside CP and Interview Pack: list Patterns, Questions and the Bug Gallery
- A contest problem whose answer is stored iterators
- Pattern 1: the LRU cache, the interview classic
- Pattern 2: Josephus, the circle that wraps
- Pattern 3: erase, then step back
- Pattern 4: the reverse flag on a list
- Pattern 5: splice to rearrange in O(1)
- Nine interview questions, with model answers