Easy · Hash Set
Understand → Visualise → Practice.
A set answers membership queries in average O(1) time, so a repeated value can be detected during one scan.
If a value is already in the set, return true; otherwise insert it and continue.
It starts empty.
A hit proves a duplicate.
No hit means all values are unique.
O(n) expected time and O(n) space.
Sorting also works but changes the input and costs O(n log n).
Read the full guide first: Hash Maps and Hash Sets.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.