3Sum
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at 3Sum is returning duplicate triplets, and Microsoft candidates reported this one in September 2026. The task is simple to state: find every unique triplet in an integer array that sums to zero, sorted inside and out. It's a sorting plus two-pointers problem, and the logic is well worn. The trap is in the dedup details, not the idea. If you've got the OA in a day or two, nail the skip-duplicates step and you're most of the way there. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment.
The problem
Given an integer array nums, return every unique triplet [a, b, c] whose values 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[]) → int[][] Examples Example 1 nums = [-1,0,1,2,-1,-4] return = [[-1,-1,2],[-1,0,1]] These are the only two distinct value triplets with sum zero. Example 2 nums = [0,0,0,0] return = [[0,0,0]] The same value triplet is returned only once. Constraints 0 <= nums.length <= 3000. -100000 <= nums[i] <= 100000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array first. Then loop i from 0 to n-3. If nums[i] is greater than 0, break, since no triplet can reach zero. If nums[i] equals nums[i-1], skip it. Set left to i+1 and right to the end. Compare the sum to zero and move the pointers inward. When you hit zero, record the triplet, then advance left and retreat right past every repeated value. Skipping duplicates only at the outer loop is the classic error, and [0,0,0,0] exposes it fast. Using a set of tuples works but is slower and sloppier. Complexity is O(n^2) time, which handles 3000 elements fine. Because you sort first, each triplet is already in ascending order and the result list is already lexicographic. Empty and tiny arrays should return an empty list. If you blank on the pointer movement during the live OA, StealthCoder is the hedge that gets you a clean solution.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill 3Sum 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. If you're reading this with an OA window open, you're who this was built for.
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 Microsoft's OA.
Microsoft reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
3Sum FAQ
How hard is 3Sum really?+
It's medium on paper, but the logic is short once you know it. Most failures come from duplicate handling, not the core idea. If you've seen two-pointers on a sorted array, you can finish this in about 15 minutes.
What's the trick to avoiding duplicate triplets?+
Sort first. Skip an outer value if it equals the previous one. After finding a valid triplet, move both pointers past all equal neighbors. That covers every duplicate case, including [0,0,0,0], which should return a single [0,0,0].
Do I need to sort the output myself?+
Usually not. Sorting the input means each triplet is built in ascending order, and iterating i, then left, in order produces triplets lexicographically. Still, run the examples to confirm the output order matches what the problem expects.
Is a hash set approach acceptable?+
It can pass, but it's messier. You'd store tuples in a set to dedupe, then sort at the end. Two pointers is cleaner, uses less memory, and avoids subtle bugs. With n up to 3000, O(n^2) is the target either way.
How do I prepare for this in 48 hours?+
Write 3Sum from scratch three times without looking. Then test edge cases: empty array, all zeros, all positives, and heavy repeats. Once the duplicate-skip loops feel automatic, move on to two-pointer variants like 3Sum Closest.