#C3096. Find Pairs with a Specific Absolute Difference

    ID: 46485 Type: Default 1000ms 256MiB

Find Pairs with a Specific Absolute Difference

Find Pairs with a Specific Absolute Difference

You are given an array of integers and an integer \(k\). Your task is to determine whether there exist two distinct indices \(i\) and \(j\) in the array such that the absolute difference of the corresponding elements is exactly \(k\). That is, you need to check if there exists a pair \((i, j)\) such that

[ |nums[i] - nums[j]| = k ]

If such a pair exists, output "YES", otherwise output "NO". Make sure to consider all possible pairs in the array.

Note: The pair \((i, j)\) is considered only if \(i \neq j\).

inputFormat

The input is given via standard input (stdin) and has the following format:

  • The first line contains an integer \(T\), the number of test cases.
  • For each test case, there are two lines:
    • The first line contains an integer \(k\).
    • The second line contains a space-separated list of integers representing the array \(nums\).

It is guaranteed that the number of test cases is at least 3.

outputFormat

For each test case, output a single line containing either "YES" if there exists a pair of indices satisfying \(|nums[i] - nums[j]| = k\), or "NO" otherwise. The output should be printed to standard output (stdout).

## sample
4
5
10 15 3 7
3
1 2 3 4
6
1 5 9 14
1
1
YES

YES NO NO

</p>