Easy O(N) soln C++


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

#2

Nice one, I solved using binary search.
This one is cool


#3

thats cool! thanks man!


#4

HariAcidReign123 this is O(n^2) solution not O(n) sol. Try dry run it, u will find out…


#5

not exactly correct need to add if(i==j) j++ inside the else statement