#K5331. Check for Duplicates in an Array
Check for Duplicates in an Array
Check for Duplicates in an Array
You are given an integer array of size \( n \). Your task is to determine whether there exist two distinct indices \( i \) and \( j \) (with \( 1 \le i < j \le n \)) such that \( arr[i] = arr[j] \). If such a pair exists, print YES; otherwise, print NO.
Input Format: The first line of the input contains an integer \( T \), representing the number of test cases. Each test case consists of two lines: the first contains a single integer \( n \) (the number of elements in the array), and the second contains \( n \) space-separated integers representing the array.
Output Format: For each test case, output a single line containing either YES if a duplicate exists, or NO if the array has all distinct elements.
For instance, given the array \( arr = [1, 3, 3, 2, 2, 1] \) with \( n = 6 \), since \( arr[2] = arr[3] = 3 \), the output should be YES.
inputFormat
The input is read from stdin
and has the following format:
T n arr[0] arr[1] ... arr[n-1] ... (repeated T times)
Here, \( T \) is the number of test cases, and for each test case, \( n \) is the number of elements in the array, followed by \( n \) space-separated integers.
outputFormat
For each test case, output a single line to stdout
containing YES if there exists a duplicate, otherwise output NO.
2
5
1 2 3 4 5
6
1 3 3 2 2 1
NO
YES
</p>