Maximum two pointer approach

why we have taken j=sizeof(a)/size of(int)-1;
when we have already know the element there and please explain me this logic if this is used in some other type q

j=sizeof(a)/size of(int)-1;
this has been used bcoz we are not inputting the array… simply defining in code… so to find the value of j we are doing this…
rest if u have any other doubt pls share ur code i will help u out

and if we input the array then what we should take j

please reply me if we input then j=n-1;

why at last when cs==s j-- and i++why we used at last please explain me

and also explain me if we are inputing array then we can write j=n-1;

yes when inputting array then we have to write j=n-1;

@tarshid7 go through video lecture pls… all ur doubts would be cleared… i don’t understand when video lecture are available and bhaiya has explained everything over there then why u ask these kind of doubts

I just only want to clear it once

what more doubts u have… share ur code if u still have any queries

only at last when cs==s then why we are inputing I++ and j-- please explain me this one

so when cs == s means we already have found one ans… now to explore all other possibilities if we just increment i then our overall ans will become more and if we just decrement j then overall ans becomes less… so to balance the both we i++ and j-- and check for all other potential ans…
hope it clears all ur doubts

yes thanks for the help

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.

and please tell me that two pointer approach can be only used in sorted array and if there are unsorted array then we have to sort it first then apply two pointer approch

yes… it can be applied only in sorted arrays

so when there will be unsorted array we first have to sort it then apply two pointer approch

yes… u would have to sort then