3Sum with Two Pointers

medium
Unit 15 · Two Pointers & Backtracking0/3 to milestone

Implement:

  • three_sum(nums): all unique triplets [a, b, c] with a + b + c == 0. Each triplet is sorted, and the list of triplets is sorted. Run in O(n²) by sorting first and using two pointers, skipping duplicates.
  • three_sum_closest(nums, target): the sum of three elements closest to target (if two sums are equally close, return the smaller one)
#two-pointers#sorting#arrays2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
3Sum with Two Pointers · TechGradify