FastPrepMerge Two Arrays Into Sorted Order
Problems/Merge Two Arrays Into Sorted Order

Merge Two Arrays Into Sorted Order

NVIDIA logoNVIDIA● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asked to merge two arrays into sorted order or write a sort. The judged core task matches the visible source at about 95%; inputs are not assumed pre-sorted, and examples plus numeric bounds are specified for practice.

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.

More NVIDIA problems

  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Query a Header-Encoded MatrixOA · Seen Oct 2026
  • Maximum ScoreOA · Seen Oct 2026
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[] mergeTwoArraysSorted(int[] a, int[] b) {
      // Write your code here.
    }
}
Checking account…