FastPrepThree Sum: Unique Target Triplets
Problems/Three Sum: Unique Target Triplets

Three Sum: Unique Target Triplets

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives unique triplets with a target sum, sorting with two pointers, skipping duplicates, O(n^2) time, O(1) extra space, and a follow-up on memory for large input. It does not give the output order, input limits, a function signature, or an exact model of external memory. Our version is about 95% the same as the reported question.

Given an integer array nums and an integer target, return every distinct value triplet whose sum equals target.

  • Sort the three values in each triplet from smallest to largest.
  • The returned list must contain no duplicate value triplets.
  • Return the triplets in lexicographic order.

You may reorder nums. Use 64-bit arithmetic for every three-value sum. The target complexity is O(n^2) time and O(1) auxiliary space, excluding the returned triplets and the sorting implementation's call stack.

Large-input follow-up

If the array cannot fit in memory, discuss how external sorting can produce an on-disk ordered sequence and how buffered scans trade additional I/O for bounded memory.

Function

threeSumTarget(nums: int[], target: int) → int[][]

Examples

Example 1

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

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

Example 2

nums = [2,2,2,2]target = 6return = [[2,2,2]]

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

Example 3

nums = [1,2,3,4,5,0,-1]target = 6return = [[-1,2,5],[-1,3,4],[0,1,5],[0,2,4],[1,2,3]]

These are all five nondecreasing value triplets whose sum is 6, listed in lexicographic order.

Example 4

nums = [1,2,4,8]target = 100return = []

No three values sum to 100.

Constraints

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

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 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
  • 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

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
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] threeSumTarget(int[] nums, int target) {
      // Write your code here.
    }
}
Checking account…