FastPrep3Sum
Problems/3Sum

3Sum

Agoda logoAgoda● MediumONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real Agoda onsite interview report. The report directly named 3Sum, but it did not include the exact function interface, examples, constraints, or result ordering. The core task match is about 90%.

Given an integer array nums, return every unique triplet of values [a, b, c] whose elements come from three distinct indices and sum to 0.

Output Rules

  • Sort each triplet in ascending order.
  • Sort the list of triplets lexicographically.
  • Do not return duplicate triplets.

Function

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

Examples

Example 1

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

Example 2

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

The same value triplet is returned only once.

Constraints

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

More Agoda problems

  • Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Can Place FlowersPHONE SCREEN · Seen Nov 2026
  • Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
All Agoda interview questionsSee Agoda hiring insights
Saved
class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
      // write your code here
    }
}
Checking account…