Skip to the content.

1. Input Validation:

2. Sorting:

3. Loop Over the Array:

4. Two-Pointer Approach:

5. Triplet Sum Calculation:

6. Checking for Zero Sum:

7. Adjusting Pointers:

8. Returning the Result:

9.Time Complexity :

The code’s time complexity is O(n^2) due to the nested loops and the sorting step, where “n” is the length of the input array arr. The use of a set ensures that duplicate triplets are not included in the result.