FastPrepThree Sum: Unique Zero-Sum Triplets
Problems/Three Sum: Unique Zero-Sum Triplets

Three Sum: Unique Zero-Sum Triplets

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the goal of unique triplets that sum to zero, the sorted two-pointer method, a follow-up on skipping duplicates, and O(n^2) complexity. It does not give the output order, input limits, or a function signature. Our version is about 96% the same as the reported question.

Given an integer array nums, return every distinct value triplet whose elements come from three distinct indices and whose sum is 0.

  • Each triplet must be nondecreasing.
  • The returned list must contain no duplicate value triplets.
  • Return the triplets in lexicographic order.

Use 64-bit arithmetic when computing sums.

Function

threeSum(nums: int[]) → List<List<Integer>>

Examples

Example 1

nums = [-1,0,1,2,-1,-4]return = [[-1,-1,2],[-1,0,1]]

The two distinct value triplets with sum 0 are [-1,-1,2] and [-1,0,1].

Example 2

nums = [0,0,0,0]return = [[0,0,0]]

Many index triples exist, but they all produce the same value triplet, so [0,0,0] appears once.

Example 3

nums = [1,2,-2,-1]return = []

No three values sum to 0.

Constraints

  • 3 <= nums.length <= 3000.
  • -10^9 <= nums[i] <= 10^9.

More Google Onsite Interview questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • 4SumAmazon · ONSITE INTERVIEW
  • Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
  • 3SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • 3SumMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Next and Previous Lexicographic PermutationAdobe · ONSITE INTERVIEWAdobe interview questions
  • Sort ColorsInfosys · ONSITE INTERVIEWInfosys interview questions

Interview reports that mention this question

  • Google Intern Grid and Tree Rounds: 7 Experiences (Part 2 of 8)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
      // Write your code here.
    }
}
Checking account…