I wrote this code in C++ as part of a uni task where I need to ensure that there are no duplicates within an array:
// Check for duplicate numbers in user in
fast O(N) time and space solution return first when it hits duplicate
template bool containsDuplicate(vector& items) { return any_of(items.begin(), items.end(), [s = unordered_set{}](const auto& item) mutable { return !s.insert(item).second; }); }