In this case, we are taking a hardcode array as an input, what if we are asking the user to give an input, in that case, how will the program gonna perform?
Two Pointer Approach
@sonali2105
The algorithm remains same. Lets say we take an array of size n.
In that case , the left pointer , say i will be initialised with 0 only ( same as before ).
i = 0 ; ( left pointer )
The right pointer will be initialised as n-1
j = n-1 ; ( right pointer )
The rest of algorithm remains same.
Note that the array must be sorted. If it is not already sorted , then first sort it and then implement the two pointer approach.
Thanks @tarun luthra for resolving my query.Now,I am clear with the conceptt.