What's the problem


#1

/**

  • @input A : Integer array

  • @input n1 : Integer array’s ( A ) length

  • @input B : Integer

  • @Output Integer
    /
    int diffPossible(int
    A, int n1, int B) {
    int i=0;
    int j=n1-1;
    while(i>j)
    {
    if((A[j]-A[i])==B)
    return 1;
    if((A[j]-A[i])<B)
    i++;
    if((A[j]-A[i])>B)
    j–;

    }
    return 0;

}


#2

i = 0 and j = n1 - 1 so while(i> j) will never run. Even if you make it while(i<j) then also i++ and j-- logic wont be able to solve this problem as both will decrease the diff and you have to option to increase the diff. So you have to take both pointer at starting of array.