Short&Easy C++ solution using sliding window concept


#1

int Solution::diffPossible(vector &A, int B) {
int wr=1;
int wl=0;

while(wr<A.size()){
    if(A[wr]-A[wl]==B)
    return 1;
    
    else if(A[wr]-A[wl]>B&&wr-wl>1)
    wl++;
    
    else
    wr++;
}
return 0;

}