Sets: unique values
Read · 1 of 4
A set ignores duplicates
set<int> seen; holds each value at most once, kept sorted. seen.insert(x) adds x (nothing happens if it's already there), and seen.count(x) is 1 if x is in it, otherwise 0.
unordered_map and unordered_set work the same way but don't keep order, and are usually faster. You'll use both all the time in DSA.