Reported September 2026
Nvidiasorting

Merge Two Arrays Into Sorted Order

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

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

Nvidia reported this one in September 2026, and the name sounds like a warmup. Merge two arrays, return them sorted. The twist is the word "merge" tempts you into a two-pointer walk, which only works if both inputs are already sorted, and here they aren't. Each array holds up to 10^4 values, so you're sorting at most 20,000 numbers. The pattern is sorting, plain and simple. If you blank on the OA, StealthCoder runs invisibly as a safety net and puts a clean solution on screen. Most people won't need it, but know the trap before you start.

The problem

You are given two integer arrays a and b. The arrays are not necessarily sorted.
Return a new array that contains every value from a and every value from b in non-decreasing order.
Equal values may come from either array; preserve all copies.

Function
mergeTwoArraysSorted(a: int[], b: int[]) → int[]

Examples
Example 1
a = [1,3]
b = [2,4]
return = [1,2,3,4]
The combined values are 1, 3, 2, 4. Sorted non-decreasing order is 1, 2, 3, 4.
Example 2
a = [5,1]
b = [4]
return = [1,4,5]
a is not sorted. Merging and sorting produces 1, 4, 5.

Constraints
0 <= a.length, b.length <= 10^4.
-10^9 <= a[i], b[j] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to not overthink it. Concatenate a and b into one array, then sort it. That's O((n+m) log(n+m)), which is trivial for 20,000 elements. Brute force like repeated insertion into a sorted list or selection sort is O(n^2) and would still pass at this size, but it's sloppy and shows poor judgment. The common pitfall is writing the classic merge from merge sort without sorting each input first. That gives wrong output on example 2 where a is [5,1]. Another trap is deduplicating, which breaks the rule to preserve all copies. Also handle empty arrays, since either length can be 0. Values reach 10^9 in magnitude, so default int is fine in most languages, but avoid subtracting values in a custom comparator because that can overflow. If you freeze mid-assessment, StealthCoder is the hedge that gives you the working version live.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Merge Two Arrays Into Sorted Order 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Nvidia reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Merge Two Arrays Into Sorted Order FAQ

How hard is the Nvidia Merge Two Arrays problem really?+

Easy. It's a concat-and-sort problem with 10^4 max length per array. The only way to fail is overcomplicating it or assuming the inputs are sorted. Write it in a few lines, then test with empty arrays and duplicates before submitting.

What's the trick to Merge Two Arrays Into Sorted Order?+

The inputs are not sorted, so a two-pointer merge alone is wrong. Combine both arrays and sort the result, or sort each one first and then merge with two pointers. Both are correct. Concat then sort is shorter and harder to bug.

Do I need to remove duplicates?+

No. The problem says to preserve all copies, including equal values from either array. If a has 3 and b has 3, the output has two 3s. Don't use a set. Keep every element and let the sort place them in non-decreasing order.

What edge cases should I test before submitting?+

Test both arrays empty, one array empty, all duplicates, negative values near -10^9, and an unsorted first array like [5,1]. Also confirm you return a new array rather than mutating and returning one of the inputs, since the prompt asks for a new array.

How do I prepare for this in 48 hours?+

Skip deep study. Practice writing a sort with a comparator in your language, and practice a two-pointer merge of sorted arrays. That covers every variant of this problem. Then do two or three easy array problems under a timer so the syntax is fast and automatic.

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

OA at Nvidia?
Invisible during screen share
Get it