Your question is Optimize Duplicate Detection in Arrays. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.
Implement a function contains_duplicate(nums) that takes a list of integers nums and returns a boolean:
True if any value appears at least twiceFalse if all values are distinctdef contains_duplicate(nums):