Find Pair Given Difference
Binary Search
easy
Score: 20
Given an array Arr[] of size L and a number N, you need to write a program to find if there exists a pair of elements in the array whose difference is N.
Input Format
The first line of input consists of two space-separated integers. L and N. The second line of input consists of L space-separated integers.
Output Format
The output should consist of a single integer, either 0 or 1. 1 if exists and 0 if doesn’t.
Example 1
Input:
6 78
5 20 3 2 5 80
Output:
1
Explanation:
Explanation: (2, 80) have a difference of 78.
Example 2
Input:
5 45
90 70 20 80 50
Output:
0
Explanation:
There is no pair with a difference of 45.
Constraints
- 1 ≤ L ≤ 104
- 1 ≤ Arr[i], N ≤ 105
- Expected Time Complexity: O(L* Log(L)).
- Expected Auxiliary Space: O(1).