Optimal Algorithmic Approach
Sort + Two-Pointer: O(n²) overall, skipping duplicate values at each pointer to avoid duplicate triplets.
Core Invariants & Edge Cases
- Sort the array first
- Fix one element, then use two-pointer on the remaining sorted segment
- Skip duplicates carefully for the fixed element and both pointers