3Sum
Updated
Problem statement
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.
Each returned triplet must be sorted in ascending order. Return the complete list of triplets in lexicographic order, without duplicates.
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 unique value triplets that sum to 0 are [-1,-1,2] and [-1,0,1].
Example 2
nums = [0,0,0,0]return = [[0,0,0]]All valid index choices produce the same value triplet, so [0,0,0] appears only once.
Constraints
3 <= nums.length <= 3000.-100000 <= nums[i] <= 100000.
Source note: Author-written prompt excerpt retained for source fidelity.
More Optimus Information Onsite Interview questions
- Apply Overridden Integer TransformsONSITE INTERVIEW · Seen Oct 2026
- Compute Areas Through an Abstract Shape TypeONSITE INTERVIEW · Seen Oct 2026
- Dispatch Virtual Shipping PricesONSITE INTERVIEW · Seen Oct 2026
- N-Queens Solution CountONSITE INTERVIEW · Seen Oct 2026
- Two SumONSITE INTERVIEW · Seen Oct 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
- Count Triplets With Sum at Most TargetGoogle · ONSITE INTERVIEWGoogle interview questions
- Sort ColorsCapital One · ONSITE INTERVIEWCapital One interview questions
- 3SumMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
- Next and Previous Lexicographic PermutationAdobe · ONSITE INTERVIEWAdobe interview questions
- Sort ColorsInfosys · ONSITE INTERVIEWInfosys interview questions