O(nlogn) time complexity, constant space, 5 line solution


#1
int Solution::diffPossible(vector<int> &A, int k) {
    for(int i=0;i<A.size();++i){
        auto comp=lower_bound(A.begin()+i+1,A.end(),A[i]+(long long)k);
        if(comp!=A.end() and *comp==A[i]+(long long)k) return 1;
    }
    return 0;
}