Learn C++ STL

Lesson 6 of 9 · vector: The Container You Reach for First

Module 2 · vector: The Container You Reach for First

CP and Interview Pack: vector Patterns, Questions and the Bug Gallery

ProReading

Codeforces Round 111 (Div. 2) opened with problem 160A, "Twins". You get n coins. Take as few as you can so that your share is strictly larger than what is left. Bob tried subsets in his head. Amara read the coins into a vector, sorted it and took the largest first. Her whole solution is pattern 1 below.

Checking what this lesson needs for you…

What is inside CP and Interview Pack: vector Patterns, Questions and the Bug Gallery

  1. Pattern 1: read n, then n values
  2. Pattern 2: a grid and its four neighbours
  3. Pattern 3: prefix sums, with the off-by-one handled
  4. Pattern 4: two pointers over a sorted vector
  5. Pattern 5: erase-remove
  6. Six interview questions, with model answers
CP and Interview Pack: vector Patterns, Questions and the Bug Gallery | Learn C++ STL | Progsity