O(n) time and O(1) space cpp sol


#1
int n = A.size();
int i=0,j=1;
while(i<=j&&j<n)
{
    if(i==j)j++;
    if(A[j]-A[i]==k) return 1;
    if(A[j]-A[i]<k) j++;
    if(A[j]-A[i]>k) i++;
}
return 0;