easyArrays & HashingPure DSA~10 min
Duplicate Username Check
A signup batch importer must reject the whole file if any username appears twice — duplicates would collide on the unique index. Decide quickly whether the batch contains any repeat.
Problem
Given an array of integer username hashes, return true if any value appears at least twice, and false if every value is distinct.
Input
An array nums of length n (1 ≤ n ≤ 10^5), values in [-10^9, 10^9].
Output
A boolean — true if a duplicate exists.
Constraints
- 1 ≤ n ≤ 100,000
- Values may be negative
- Return as soon as a duplicate is found
Examples
Example 1
Input
nums = [1, 2, 3, 1]
Output
true
The value 1 appears at indices 0 and 3.
Example 2
Input
nums = [1, 2, 3]
Output
false
All three values are distinct.