If the length of chopsticks are [1 3 4] and D =3.
Then according to the approach discussed, we start with 1 and try to pair it with 3 ie the next element but it can’t be paired and we remove 1 from the list. Then we check for 3 , it can’t also be paired . so, our answer would be 0 but the answer should be 1 as 1 can be paired with 4 as the difference in their lengths satisfy the condition.
Query regarding the algorithm
@7nishit Yes you are correct just check from the correct position that whether any element exist in the map with Current element+ D . If yes proceed with next value and update the sum.
Then the complexity is O(nlogn)
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.