Three Sum: Unique Zero-Sum Triplets
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that matters in this Google OA, reported September 2026, is example two: [0,0,0,0] returns a single [0,0,0]. Many index triples, one value triplet. That's the whole problem. It's Three Sum, and the pattern is sort plus two pointers. The array goes up to 3000 elements with values up to 10^9, so brute force is dead and 64-bit sums are required. If you blank on the duplicate skipping, StealthCoder runs invisibly during the live assessment and gives you the working solution as a safety net. Otherwise, the script is below.
The problem
Given an integer array nums, return every distinct value triplet whose sum is 0. Each triplet must be nondecreasing. The returned list must contain no duplicate value triplets. Return the triplets in lexicographic order. Use 64-bit arithmetic when computing sums. Function threeSum(nums: int[]) → int[][] Examples Example 1 nums = [-1,0,1,2,-1,-4] return = [[-1,-1,2],[-1,0,1]] The two distinct value triplets with sum 0 are [-1,-1,2] and [-1,0,1]. Example 2 nums = [0,0,0,0] return = [[0,0,0]] Many index triples exist, but they all produce the same value triplet, so [0,0,0] appears once. Example 3 nums = [1,2,-2,-1] return = [] No three values sum to 0. Constraints 3 <= nums.length <= 3000. -10^9 <= nums[i] <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array first. That gives you nondecreasing triplets and lexicographic output for free. Then fix index i, and run two pointers, left at i+1 and right at the end. If the sum is too small, move left up. Too big, move right down. On a hit, record it and move both. The trick is duplicates. Skip nums[i] if it equals nums[i-1]. After a hit, skip repeated values on both pointers. Most failures come from skipping in the wrong place and dropping valid triplets like [-1,-1,2]. Another pitfall is 32-bit overflow, since three values near 10^9 will break int math. Use long. Time is O(n^2), space is O(1) beyond output. If you freeze on the live OA, StealthCoder is the hedge. It reads the problem on screen and hands you the sorted two-pointer solution without the proctor seeing anything.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Three Sum: Unique Zero-Sum Triplets cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as 3sum. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Three Sum: Unique Zero-Sum Triplets FAQ
How hard is this Google Three Sum question really?+
Medium difficulty, but it's a classic. The algorithm is short. The risk is edge cases: duplicates, all zeros, and overflow. If you've seen sort plus two pointers once, you can finish it in 15 minutes. Without that, you'll likely drift toward a slow hash set approach.
What's the trick to avoiding duplicate triplets?+
Sort first, then skip equal values. Skip nums[i] when it matches nums[i-1]. After finding a valid triplet, advance left and right past any repeated values. Don't skip before checking, or you'll lose cases like [-1,-1,2] where the repeat is legitimate.
Do I need to sort the output separately?+
No. If you sort nums first and iterate i, left, right in order, triplets are found in lexicographic order and each is already nondecreasing. Just append as you go. Sorting the result again is wasted work and can hide bugs.
Why does the problem mention 64-bit arithmetic?+
Values go up to 10^9 in magnitude, so three of them sum to 3 * 10^9, past the 32-bit int limit. In Java or C++, use long for the sum. Python handles it natively. Missing this fails only on large hidden tests.
How do I prepare for this in 48 hours?+
Write the sorted two-pointer solution from memory twice. Then test it on [0,0,0,0], [-1,0,1,2,-1,-4], and an all-positive array. Check that duplicates are skipped correctly and sums use 64-bit. That covers nearly every failure mode for this pattern.