Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

3Sum

Python data engineering interview problem. Difficulty: beginner. Pattern: Two Pointers. About 10 minutes. Part of the Pro drill bank.

All unique triplets that sum to zero, sorted. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement three_sum(nums: list) -> list returning unique triplets that sum to 0. Each triplet sorted ascending; outer list sorted.

Requirements

  • Triplets sorted ascending.
  • Sorted unique zero-sum triplets.

Constraints

  • Outer list sorted lexicographically.

Examples

Input: three_sum([-1, 0, 1, 2, -1, -4]) Output: [[-1, -1, 2], [-1, 0, 1]] Two distinct triplets.

Topics: lakebench, python, triplets, sorted.

More Python interview questions · All interview problems · Learn data engineering

beginner

3Sum

Interview-style drill: All unique triplets that sum to zero, sorted.

Implement `three_sum(nums: list) -> list` returning unique triplets that sum to 0. Each triplet sorted ascending; outer list sorted. Example: `[-1, 0, 1, 2, -1, -4]` → `[[-1, -1, 2], [-1, 0, 1]]`. Keep the harness.