#K81577. Find Pair with Target Difference
Find Pair with Target Difference
Find Pair with Target Difference
You are given an array of integers and a target integer T. Your task is to determine whether there exists a pair of distinct indices i and j such that the absolute difference between ai and aj is exactly T. In mathematical notation, you need to check if there exist indices i and j (with i ≠ j) for which
For example, if the array is [1, 5, 9, 13] and T is 4, the answer is True because \(|1-5|=4\). Otherwise, if no such pair exists, return False.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains two integers n and T, representing the number of elements in the array and the target difference respectively.
- The second line contains n integers separated by spaces, representing the array elements.
outputFormat
Output to standard output (stdout) a single line with either True
or False
indicating whether such a pair exists.
4 4
1 5 9 13
True