Mark As Completed Discussion

However, it likely will not be the target immediately. Thus, we apply this logic: if the sum of the values is less than the target value, we increment the left pointer (move your left pointer pointer_one one index rightwards).

And if the sum is higher than the target value, we decrement the right pointer (correct the position of your pointer pointer_two if necessary).

1} else if (sum < target) {
2  i++;
3} else {
4  j--;
5}