I doesnot understand why sir increase the pointer from i to i+1 if we are not able to make pair of l [i ] with l [ i+1 ] but its is a possiblity that l [i ] make a pair with l [i+2 ] so why we are not comparing i with i+2

for eg:-
chopstick[ ] ={ 1, 3, 5, 7, 9};
and D= 4
first we compare l [ 0] with l [ 1 ] not we cannot make a pair of diff. 4
so we are increasing i from 0 to 1 and again checking the pair l[1 ] with l[ 2] . ijn this way we doesnot get any pair
but there is one pair present (1,5) whose d=4;
so how can we achieve this

D is max difference between two chopsticks

algorithm of Problem

numpairs = 0
for ( i = 1; i < N; )
    if (L[i] >= L[i+1] -D)  // L[1] and L[2] can be paired
        numpairs++,         // pair them up
        i += 2;
    else
        i++;                // eliminate L[1]

for this example
1,3,5,7,9
ans is 2
1,3 and 5,7

this is given in the question that D
is the max diffrence between the two chopsticks ??

if we take take D=4 then this algorithm doesnot give the correct answer

yes

so, for this example 1,3,5,7,9,
we cannot take D=4

why not D can be 4??

so how answer becomes (1,3 ) and ( 5,7) when D=4

use the algorithm mention above
1,3 difference is 2<4 so it will be ans
5,7 difference is 2<4 so it will be ans

got it now thanks a lot !!

please see this code and tell my mistake
Coding Blocks IDE

problem in taking input in vector now i solve it .
thanks !

If your doubt is resolved plz Mark it as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.