Basic example
Input
nums = [1, 3, 5, 9], k = 4
Output
True
3 and 7 would be a candidate but 5 and 1 differ by 4 (5 - 1 = 4). There exists a pair with difference 4.
Full lesson preview
Given a sorted array of integers and a non-negative integer K, determine whether any two distinct elements have an absolute difference equal to K.
Problem statement
Task
Examples
Input
nums = [1, 3, 5, 9], k = 4
Output
True
3 and 7 would be a candidate but 5 and 1 differ by 4 (5 - 1 = 4). There exists a pair with difference 4.
Input format
Output format
Constraints
Samples
Input
nums = [1,2,2,3], k = 0
Output
True
There are duplicate elements (2 and 2) so difference 0 exists.