#include <set>
set<int> s = {5, 2, 8, 2, 1, 5};
// Stored as: {1, 2, 5, 8} — sorted, no duplicates
s.insert(3); // {1,2,3,5,8}
s.erase(2); // {1,3,5,8}
s.count(3) // 1 (present)
s.count(99) // 0 (absent)
for (int x : s) cout << x; // always sorted
Write intersection(vector<int> a, vector<int> b) that returns a sorted vector of elements present in both inputs, with no duplicates in the result.
Click "Run" to execute your code.