Reported August 2026
Temutwo pointers

Merge Two Sorted Collections Without Duplicates

Reported by candidates from Temu's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Temu OA. Under 2s to a working solution.
Founder's read

The Temu OA reported in August 2026 looks like a merge problem, but it's really a two-pointer walk with a dedupe check bolted on. Two sorted arrays, up to 100000 elements each, and you return the sorted unique union. If you've done merge sort's merge step, you've done 90% of this. The risk isn't the idea, it's the edge cases: empty arrays, runs of duplicates, and negative values. StealthCoder is the safety net if your mind goes blank mid-assessment, but the pattern below should be enough to walk in with.

The problem

You are given two integer arrays first and second, each sorted in nondecreasing order.
Return one nondecreasing integer array that contains every value appearing in either input exactly once. Duplicate occurrences within one input or across both inputs must contribute only one value to the result.

Function
mergeSortedUnique(first: int[], second: int[]) → int[]

Examples
Example 1
first = [1,2,2,4]
second = [2,3,4,4,5]
return = [1,2,3,4,5]
The value 2 appears in both inputs and 4 appears more than once, but each is included only once in the merged result.
Example 2
first = []
second = [-3,-3,0,7]
return = [-3,0,7]
The first input is empty. Removing the repeated -3 from the second input leaves the complete result.
Example 3
first = [1,1,1]
second = [1,1]
return = [1]
All elements have the same value, so the unique union contains one element.

Constraints
0 <= first.length, second.length <= 100000.
-10^9 <= first[i], second[i] <= 10^9.
Both input arrays are sorted in nondecreasing order.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: both inputs are already sorted, so don't reach for a set and a re-sort. That works but costs O(n log n) and ignores the gift in the constraints. Use two pointers, i and j. At each step, pick the smaller of first[i] and second[j], and append it only if the result is empty or differs from the last appended value. Advance the pointer you took from. When values are equal, either one works, since the last-value check drops the duplicate. Then drain whichever array has leftovers using the same check. That's O(n+m) time and O(1) extra beyond the output. Common pitfalls: comparing against the input neighbor instead of the last output value, forgetting to drain the tail, and crashing on an empty array. Check [] with [-3,-3,0,7] and [1,1,1] with [1,1] before submitting. If you freeze during the live OA, StealthCoder can hand you the clean two-pointer version.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Merge Two Sorted Collections Without Duplicates 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Temu's OA.

Temu reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Two Sorted Collections Without Duplicates FAQ

How hard is the Temu merge sorted unique problem really?+

Easy. It's the merge step from merge sort plus a duplicate check. The only real way to fail is overcomplicating it or missing edge cases like empty inputs. If you can write two pointers cleanly, you can finish this in a few minutes.

What's the trick to solve it fast?+

Walk both arrays with two pointers, take the smaller value, and only append it if it differs from the last value in your result. That one comparison handles duplicates within an array and across both arrays. Then drain the leftovers with the same check.

Can I just use a set and sort?+

You can, and it's correct. It runs in O(n log n) with extra memory. With 100000 elements per array it's fine for most checkers, but the two-pointer version is linear and shows you noticed the arrays are sorted. Prefer two pointers if you have the choice.

Which edge cases should I test before submitting?+

Test an empty first array, an empty second array, both empty, all-identical values like [1,1,1] with [1,1], and negative numbers. Also check a case where one array finishes early so the tail drain runs. Those cover nearly every bug people hit here.

How do I prepare for this in 48 hours?+

Write the merge step from scratch twice without looking. Then add the last-appended dedupe check and run the three examples by hand. Also rehearse the related pattern of removing duplicates from a sorted array. That's enough for this problem and its close variants.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Temu.

OA at Temu?
Invisible during screen share
Get it