3Sum
Reported by candidates from Agoda's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Agoda reported this one in July 2026, and the detail that matters is in the output rules: sorted triplets, a lexicographically sorted list, and no duplicates. That's 3Sum, and the dedup is where people lose points, not the math. Example 2 shows it plainly: [0,0,0,0] returns a single [0,0,0]. If you've seen this before, you're fine. If your brain goes blank on the duplicate skipping, StealthCoder is the invisible safety net running during the live OA. Either way, you know the shape now: sort, fix one number, squeeze the other two.
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]] Example 2 nums = [0,0,0,0] return = [[0,0,0]] The same value triplet is returned only once.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Sort the array first. Then loop i from the start, and for each i run two pointers, left at i+1 and right at the end. If the sum is below zero, move left up. If it's above zero, move right down. If it's zero, record the triplet and move both. The trick is dedup without a set. Skip i when nums[i] equals nums[i-1]. After a hit, advance left and right past repeated values. Sorting up front also gives you ascending triplets and lexicographic order for free, which satisfies both output rules. Common pitfall: skipping duplicates before checking the first match, which drops valid answers like [-1,-1,2]. Also break early once nums[i] is positive. Time is O(n^2), space is O(1) beyond the output. If you freeze on the pointer-skip logic mid-assessment, StealthCoder can surface the full solution in real time without the proctor seeing it.
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 Agoda's OA.
Agoda 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 this Agoda 3Sum question really?+
It's a standard medium. The idea is well known, but the duplicate handling trips people up. If you can write sort plus two pointers and skip repeated values cleanly, you're done in under 20 minutes of actual typing.
What's the trick to avoiding duplicate triplets?+
Sort first, then skip repeated values in two places. Skip i if it equals the previous element. After finding a valid triplet, move left and right past any equal neighbors. No hash set needed, and the output stays ordered.
Do I need to sort the output myself?+
Not if you sort nums first and iterate in order. Each triplet comes out ascending, and the list of triplets is generated in lexicographic order, so both output rules are met without extra sorting.
Why not use a hash set of triplets?+
It works but it's slower in practice and wastes memory. You'd have to sort each triplet, store tuples, then sort the final list. Two pointers with skipping is cleaner and is what interviewers expect.
How do I prepare for this in 48 hours?+
Write 3Sum from scratch twice without notes. Test on [0,0,0,0] and [-1,0,1,2,-1,-4]. Then trace the duplicate skips by hand. That covers the edge cases this problem is built around.