Problem 823
Check If N and Its Double Exist
Easy · 10 pts · Array, Hash Table
Problem
Decide whether the array contains two elements at different positions i != j such that A[i] = 2 × A[j]. Zero needs care: 0 = 2 × 0, so two zeros count, but a single zero does not. Scan the array with a hash set of the values seen so far, and for each new value check whether its double or (for even values) its half is already in the set.
Input
The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1].
Output
Print YES if such a pair exists, otherwise NO.
Constraints
2 <= N <= 100000; -1000 <= A[i] <= 1000
Example input
4 10 2 5 3
Example output
YES
Explanation
In 10 2 5 3, the element 10 is twice the element 5, so the answer is YES.