#K44237. Find Pair with Given Difference
Find Pair with Given Difference
Find Pair with Given Difference
You are given an array of integers and an integer \(k\). Your task is to determine whether there exists a pair of distinct elements in the array such that the difference between them is exactly \(k\). Note that when \(k = 0\), the presence of any duplicate element is considered a valid pair. Output True
if such a pair exists and False
otherwise.
inputFormat
The input consists of two lines. The first line contains two integers \(n\) and \(k\): \(n\) (the number of elements in the array) and \(k\) (the target difference). The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single line with either True
or False
. Print True
if there exists a pair of numbers in the array whose difference is exactly \(k\); otherwise, print False
.
5 3
1 5 3 4 2
True