SIR AS MENTIONED IN VIDEO WHY WE ARE NOT DECREEMENTING THE VALUE OF i WHEN WE GET 5+12 = 17 WHICH IS LESS THAN 16 . BECAUSE IT MIGHT BE THE CASE THE CASE WE FOUND 4 BEFORE 5 WHICH RSULTS IN 12+4 =16.
Two pointer approach
please read your statement correctly i think its a typing error ( 17> 16 )
if we have 4 then the array will be 1, 3, 4, 5, 7, 10, 11, 12, 13
so in this first we will get 3 + 13 = 16, then will be do i++ and j-- so that other pairs will be found, here both i and j are changed because now as we have found the sum, so if only increase i then sum will be greater and if we only decrement j then it will decrease the sum, so here we need to change both i and j.
Feel free to ask if you still have doubt on this.
Please mark it as resolved if you got it.
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.