Problem
At Stripe, a service receives a list of integer event IDs and needs to quickly determine whether any ID appears more than once. A naive solution compares every pair of elements, but this is too slow for large inputs. Write an optimized algorithm to detect duplicates.
Formal Specification
Implement a function contains_duplicate(nums) that takes a list of integers nums and returns a boolean:
Trueif any value appears at least twiceFalseif all values are distinct
Constraints
- 1 <= len(nums) <= 10^5
- -10^9 <= nums[i] <= 10^9
- Input contains integers only
- Target solution should improve on O(n^2) brute force
Function Signature
def contains_duplicate(nums):
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.


