← All coding problems
Contains Duplicate
easyArrays & Hashing+10 XPTime limit 2s
Given an array of integers, decide whether any value appears at least twice.
Input:
- line 1:
n - line 2:
nintegers
Output: true if some value repeats, otherwise false.
Constraints: 1 ≤ n ≤ 10⁵, −10⁹ ≤ a[i] ≤ 10⁹.
Think about it: comparing every pair is O(n²) — too slow for 10⁵ numbers. Can a set remember what you have already seen?
Sample input 1
4 1 2 3 1
Sample output 1
true
Sample input 2
4 1 2 3 4
Sample output 2
false
📖 Stuck? Learn the pattern
Read input from standard input and print the answer to standard output. Your code runs in a secure sandbox against the samples (Run) and hidden tests (Submit).