#K60757. Find Pair With Specific Difference
Find Pair With Specific Difference
Find Pair With Specific Difference
Given an array of integers and an integer (k), determine if there exists a pair of distinct elements (a) and (b) in the array such that (|a - b| = k).
If such a pair exists, output YES; otherwise, output NO.
The condition can be formally expressed as: (|a - b| = k), where (a, b) are elements of the array and (a \neq b).
inputFormat
Input is read from standard input (stdin) in the following format:
1. The first line contains an integer (n), denoting the number of elements in the array.
2. The second line contains (n) space-separated integers representing the array elements.
3. The third line contains an integer (k), representing the required absolute difference.
outputFormat
Output a single line to standard output (stdout) that contains either YES or NO, indicating whether there exists a pair of elements in the array whose absolute difference is exactly (k).## sample
5
1 5 3 4 2
3
YES