Array target sum triplets

the hint video is not loading so can u give me a hint on how to solve target sum triplets?

@sktg99 It is similar to array target sum pair problem.
Step 1: First Sort the array.
Step 2: Fix an element at i. Then find the rest two elements that sum to target in the similar way you have done the array target sum pair.

Consider the sorted array: [1 2 3 4 5 6 7]
Initially

  • i points to first element
  • l points to the left of the remaining array ie. to i+1
  • r points to the right of remaining array ie. to the last element.

for every i:
if(arr[l]+arr[r]+arr[i]==target)
print the possibility, l++, r–

if(arr[l]+arr[r]+arr[i]>target)
r–

if(arr[l]+arr[r]+arr[i]<target)
l++

continue these steps till (l<r) -->after that increment i by one position and repeat the same steps.

now suppose i points to 2nd index, now left pointer points to first and right ptr points to the end,
now after first iteration suppose left pointer needs to increase then it will point to second index which is already occupied by i so that case is not possible, how should i avoid this mismatch?

The left pointer must always be initialized one step ahead of the i pointer. So when i comes to 2nd index, l must be initialized to i+1 ie. to the 3rd index. Do a dry run and check it by yourself. You will get the logic.

i got the logic, thanks