FastPrepThree Sum
Problems/Three Sum

Three Sum

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMENEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The technical round asked: "three sum".

The report does not give numeric bounds, duplicate rules, or output order. Here, return unique value triplets that sum to zero, with each triplet and the result sorted. Arrays may be empty and contain at most 100 values.

The judged task matches the report at about 85%.

Given an integer array nums, return every unique triplet of values whose sum is zero. Each triplet must use three different array positions.

Sort the values within each triplet in nondecreasing order. Return the triplets in lexicographic order: compare the first values, then the second, then the third. Different index choices with the same three values produce one result. Return an empty array if there is no valid triplet. You may reorder nums.

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 unique value triplets are [-1,-1,2] and [-1,0,1]. Both sum to zero. Reusing the other occurrence of -1 with 0 and 1 does not create another value triplet.

Example 2

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

Any choice of three positions gives [0,0,0]. Return this value triplet once.

Constraints

  • 0 <= nums.length <= 100
  • -100000 <= nums[i] <= 100000

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public List<List<Integer>> threeSum(int[] nums) {
        // Write your code here
    }
}
Checking account…