O(n) time and O(1) space c++ hi


#1

Blockquote
int Solution::diffPossible(vector &A, int B) {
if(A.size()==1){
return 0;
}
int i=0,j=0;
while(i<A.size()&&j<A.size()){
if(A[i]<A[j]+B)i++;
else if(A[i]>A[j]+B)j++;
else if(A[i]==A[j]+B && i!=j) return 1;
else i++;
}
return 0;
}