FastPrepThree Sum
Problems/Three Sum

Three Sum

Patreon logoPatreon● MediumINTERNOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Patreon software engineer intern online assessment. The candidate named this classic task: find every distinct group of three numbers that adds up to zero.

The report does not say how the answer should be ordered. Here, each triplet is sorted and the list of triplets is sorted too.

Our version is about 90% the same as the reported question.

Given an integer array nums, return all the unique triplets [nums[i], nums[j], nums[k]] such that i, j and k are three different indices and nums[i] + nums[j] + nums[k] == 0.

The answer must not contain the same triplet twice. Return each triplet in non-decreasing order, and return the list of triplets sorted in ascending order.

Function

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

Examples

Example 1

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

-1 + -1 + 2 = 0 and -1 + 0 + 1 = 0. The two -1 values give the same triplet [-1,0,1], so it appears once.

Example 2

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

The only triplet is 0 + 1 + 1 = 2, which is not 0.

Example 3

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

The only triplet adds up to 0.

Constraints

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

More Patreon interview questions

  • Sum of Subarray RegionsOA · Seen Oct 2024
  • Binary Cardinality SortingOA · Seen Apr 2023
  • Maximum Books From BundlesOA · Seen Apr 2023
  • Professors Teaching Outside Their DepartmentOA · Seen Apr 2023
  • Sliding-Window API Rate LimiterPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
  • Count Perfect PairsAdyen · OAAdyen interview questions
  • Profitable Project PairsAkuna Capital · OAAkuna Capital interview questions
  • Most Employees Working at OnceCitadel · OACitadel interview questions
  • 3SumAT&T · OAAT&T interview questions
  • Minimum Height Difference Between Distant PeaksRoblox · OARoblox interview questions
  • Minimum Machines for TasksExpedia · OAExpedia interview questions
  • Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
All Patreon interview questionsSee Patreon hiring insights
Saved
class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
        // write your code here
    }
}
Checking account…