Learn C++ STL

Lesson 6 of 9 · list and forward_list: When Elements Move and Positions Must Not

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

  1. A contest problem whose answer is stored iterators
  2. Pattern 1: the LRU cache, the interview classic
  3. Pattern 2: Josephus, the circle that wraps
  4. Pattern 3: erase, then step back
  5. Pattern 4: the reverse flag on a list
  6. Pattern 5: splice to rearrange in O(1)
  7. Nine interview questions, with model answers