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.
More AT&T Online Assessment questions
- Companies with Average Salary Above 40000OA · Seen Oct 2026
- Count Proper Prefix MatchesOA · Seen Oct 2026
- Minimum Binary Swaps to a PalindromeOA · Seen Oct 2026
- Break a PalindromeOA · Seen Oct 2025
- Advertising System Failures ReportOA · Seen Nov 2024
- Counting Triplets Divisible by DOA · Seen Nov 2024
- Project EstimatesOA · Seen Nov 2024
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
- Minimum Height Difference Between Distant PeaksRoblox · OARoblox interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
- Count Pair Sums in a RangeAdobe · OAAdobe interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions