#K55232. Find a Pair with the Given Difference

    ID: 29930 Type: Default 1000ms 256MiB

Find a Pair with the Given Difference

Find a Pair with the Given Difference

Given a sorted array of distinct integers and an integer ( k ), determine if there exists a pair of elements in the array whose difference is exactly ( k ). You are required to implement an efficient solution using the two-pointer technique.

For example, if the input is 4\n1 5 9 14\n4, the output should be True since (5 - 1 = 4).

inputFormat

Input is provided through STDIN and consists of three lines:
1. The first line contains a single integer ( n ), representing the number of elements in the array.
2. The second line contains ( n ) space-separated integers in sorted order.
3. The third line contains the integer ( k ), the target difference.

outputFormat

Print a single line to STDOUT containing ( True ) if there exists a pair of distinct elements in the array with a difference equal to ( k ); otherwise, print ( False ).## sample

4
1 5 9 14
4
True