The algorithm: Sort the array For each element nums[] (the first element of the triplet): - Skip if it's a duplicate of the previous element - Use two pointers to find pairs that sum to nums[] - left = + , right = - - Move pointers based on the sum When you find a valid triplet, skip duplicate values for both pointers Sorting enables the two-pointer technique and makes duplicate handling easier.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/two-pointers-sliding-window/3sum-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████████████