Target sum pair problem is getting time limit exceeded even when i used two pointer approach on the sorted array

Pls check code here

hello @kishoretaru
image

increment i and decrement j inside this if statement.

Can you pls explain why we need to increment i and decrement j in that loop

a)if u dont increase /decrease i,j inside that if statement then i ,j will never update due to which ur program will run into infinite loop.

b) because we already found one pair a[i]+a[j]=k to print next pair we either need to increment i or decremnt j. (doing only increment or decremnt will work).

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.