Skills101
← All practice quizzes

Quiz: STL Algorithms

5 questionsNo time limitPass: 60%+10 XP on first pass

Sort with custom comparators and lambdas, binary search with lower_bound, accumulate, count, reverse, unique, next_permutation, and the fast-I/O setup competitive programmers use.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    #include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main() {
        vector<int> v = {1, 3, 3, 5, 7};
        cout << lower_bound(v.begin(), v.end(), 3) - v.begin();
        return 0;
    }
    
  2. Question 2

    What must you do before calling unique to remove all duplicates?

  3. Question 3

    What does this print?

    #include <iostream>
    #include <vector>
    #include <numeric>
    using namespace std;
    int main() {
        vector<int> v = {2, 4, 6};
        cout << accumulate(v.begin(), v.end(), 10);
        return 0;
    }
    
  4. Question 4

    Which sorts a vector v in DESCENDING order?

  5. Question 5

    Why use ios::sync_with_stdio(false) in contests?