Last Updated: December 6, 2025
31 quizzes
Which STL container is most appropriate for a dynamic sequence with frequent random access and frequent push_back operations?
Which container guarantees unique keys and keeps elements sorted by key?
Which container adaptor uses a deque as its default underlying container in C++?
You need a container of unique integers with average O(1) lookup and no ordering requirement. Which do you choose?
Which statement about std::list and std::forward_list is TRUE?
For implementing an LRU cache where you must erase elements from the middle frequently and maintain order, which container is most suitable for the list of keys?
Which container is BEST for implementing a task scheduler where tasks are processed by highest priority first?
Which is the most cache-friendly container for iterating over a large number of numeric elements repeatedly?
You must maintain key-value pairs with possible duplicate keys and keep them sorted by key. Which container fits?
Which header must you include to use std::array?
Which utility is best suited for returning three strongly-typed values from a function without defining a custom struct?
Choose the correct STL container to store a fixed-size collection of 10 doubles with STL-style interface.
std::<double, 10> samples; Click an option to fill the blank:
Insert into an ordered set of strings
std::set<std::string> s; s.("alice");Click an option to fill the blank:
Create an unordered_map from strings to ints
std::<std::string, int> freq; Click an option to fill the blank:
What is the output of this code using a deque as a double-ended queue?
1#include <iostream>
2#include <deque>
3int main() {
4 std::deque<int> dq{1, 2, 3};
5 dq.push_front(0);
6 dq.push_back(4);
7 dq.pop_front();
8 dq.pop_back();
9 for (int x : dq) std::cout << x << ' ';
10 return 0;
11}What does this code print when using std::list and iterator operations?
1#include <iostream>
2#include <list>
3int main() {
4 std::list<int> lst{1, 2, 3, 4};
5 auto it = lst.begin();
6 ++it; // points to 2
7 it = lst.insert(it, 10); // insert before 2, it points to 10
8 ++it; // now points to 2
9 lst.erase(it); // erase 2
10 for (int x : lst) std::cout << x << ' ';
11 return 0;
12}What is the output when using std::map and operator[]?
1#include <iostream>
2#include <map>
3#include <string>
4int main() {
5 std::map<std::string, int> scores;
6 scores["Alice"] = 10;
7 scores["Bob"] = 20;
8 scores["Alice"] += 5;
9 std::cout << scores.size() << '\n';
10 std::cout << scores["Alice"] << ' ' << scores["Bob"] << '\n';
11 return 0;
12}What is the output of this program using std::unordered_set?
1#include <iostream>
2#include <unordered_set>
3int main() {
4 std::unordered_set<int> s{1, 2, 3};
5 auto r1 = s.insert(2);
6 auto r2 = s.insert(4);
7 std::cout << s.size() << '\n';
8 std::cout << std::boolalpha << r1.second << ' ' << r2.second << '\n';
9 return 0;
10}What does this priority_queue example print?
1#include <iostream>
2#include <queue>
3int main() {
4 std::priority_queue<int> pq;
5 pq.push(5);
6 pq.push(1);
7 pq.push(7);
8 pq.push(3);
9 while (!pq.empty()) {
10 std::cout << pq.top() << ' ';
11 pq.pop();
12 }
13 return 0;
14}Find the bug related to iterators and erasing from a std::vector
Click on the line(s) that contain the bug.
#include <vector>#include <iostream>int main() { std::vector<int> v{1,2,3,4,5}; for (auto it = v.begin(); it != v.end(); ++it) { if (*it % 2 == 0) { v.erase(it); } } for (int x : v) std::cout << x << ' '; return 0;}Find the bug related to using std::array
Click on the line(s) that contain the bug.
#include <array>#include <iostream>void printFirst(const std::array<int, 5>& arr) { std::cout << arr[5] << '\n';}int main() { std::array<int, 5> a{1,2,3,4,5}; printFirst(a);} Click the line that causes undefined behavior due to dereferencing an invalid iterator in a list
Click on the line to select.
#include <list>#include <iostream>int main() { std::list<int> lst{1,2,3}; auto it = lst.begin(); it = lst.erase(it); ++it; // line to inspect std::cout << *it << '\n'; return 0;}Click the line that creates an unnecessary copy when pushing into a vector of std::pair
Click on the line to select.
#include <vector>#include <utility>int main() { std::vector<std::pair<int,int>> v; std::pair<int,int> p(1,2); v.push_back(p); return 0;}Fill in the blanks to iterate over a forward_list and remove all negative values correctly.
#include <forward_list>#include <iostream>int main() { std::forward_list<int> fl{1, -2, 3, -4, 5}; auto prev = fl.(); auto it = fl.begin(); while (it != fl.end()) { if (*it < 0) { it = fl.(prev); } else { prev = it; ++it; } } for (int x : fl) std::cout << x << ' ';}Click an option to fill blank 1:
Use std::queue to process integers in FIFO order.
#include <queue>#include <iostream>int main() { std::queue<int> q; q.(1); q.(2); q.(3); while (!q.empty()) { std::cout << q.() << ' '; q.(); }}Click an option to fill blank 1:
Fill the blanks to use std::pair for a map-like insertion.
#include <map>#include <string>int main() { std::map<std::string, int> m; m.insert(std::<std::string, int>(, 42));}Click an option to fill blank 1:
Fill in the blanks to declare and access a std::tuple.
#include <tuple>#include <iostream>int main() { std::tuple<int, std::string, double> t{, , 3.14}; std::cout << std::<1>(t) << '\n';}Click an option to fill blank 1:
Match each STL container with its primary characteristic.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each associative container with its key/ordering behavior.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Order the steps to use a std::map for counting word frequencies from a vector<std::string> words.
Drag and drop to reorder, or use the arrows.
Put in order the operations to safely pop all elements from a std::stack<int> s.
Drag and drop to reorder, or use the arrows.