easyArrays & HashingPure DSA~12 min
Duplicate Receipt Finder
A payments reconciliation job ingests a batch of receipt IDs and must flag whether any receipt was double-counted. Given the list of receipt IDs, decide whether any ID appears more than once.
Problem
Given an array of integer receipt IDs, return true if any value appears at least twice, otherwise false.
Input
An array ids of length n (1 ≤ n ≤ 10^5), each value in [−10^9, 10^9].
Output
A boolean — true if a duplicate exists.
Constraints
- 1 ≤ n ≤ 100,000
- −10^9 ≤ ids[i] ≤ 10^9
- Return on the first duplicate found
Examples
Example 1
Input
ids = [4, 1, 9, 4, 2]
Output
true
4 appears twice.
Example 2
Input
ids = [4, 1, 9, 2]
Output
false
All IDs are distinct.