Kindly tell the mistake and modify it

Hey @vanshikasharma1645, for the two-pointer algorithm to run, the array has to be sorted, I’ve modified the code, you can check it here.
Another approach for solving this question can be a hashmap.