#K65967. Pair with Given Difference
Pair with Given Difference
Pair with Given Difference
Given an array of integers and an integer target, determine whether there exist two distinct indices i and j such that either
$$a_i - a_j = \text{target}$$ or $$a_j - a_i = \text{target}$$
Please note that if target = 0
, the condition is satisfied only when the same integer appears at least twice in the array.
Example:
Input: [1, 5, 3, 4], target = 2 Output: True
inputFormat
The input consists of three lines:
- The first line contains an integer
n
, which is the number of elements in the array. - The second line contains
n
space-separated integers representing the array. - The third line contains an integer
target
.
outputFormat
Output a single line containing either True
or False
depending on whether such a pair exists.
4
1 5 3 4
2
True
</p>