[IBM] OA 2025 Start – 07 Feb (Generic)

Merge 2 Arrays

Given two sorted arrays, merge them to form a single, sorted array with all items in non-decreasing order.


Example

a = [1, 2, 3]
b = [2, 5, 5]

Merge the arrays to create array c as follows:

a[0] < b[0] → c = [a[0]] = [1]
a[1] > b[0] → c = [a[0], b[0]] = [1, 2]
a[1] < b[1] → c = [a[0], b[0], a[1]] = [1, 2, 2]
a[2] < b[1] → c = [a[0], b[0], a[1], a[2]] = [1, 2, 2, 3]

No more elements in `a` → c = [a[0], b[0], a[1], a[2], b[1], b[2]] = [1, 2, 2, 3, 5, 5]

Elements were alternately taken from the arrays in the order given, maintaining precedence.


Function Description

Complete the function mergeArrays in the editor below.

mergeArrays

Parameters

  • int a[n]: a sorted array of integers
  • int b[n]: a sorted array of integers

Returns

  • int[n]: an array of all the elements from both input arrays in non-decreasing order

Constraints

  • 1 < n ≤ 5 * 10^5
  • 0 ≤ a[i], b[i] ≤ 10^9

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *