Write a function that takes two sorted arrays as input and merges them into a single sorted array. The function should return the merged array. The input arrays are already sorted in ascending order, and they may have different lengths. You can assume that both arrays contain only integers. Example: Input: Array 1: [1, 3, 5, 7, 9] Array 2: [2, 4, 6, 8, 10, 12] Output: Merged Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12] Write a function `mergeSortedArrays that takes two sorted arrays as parameters and returns a single merged array that contains all the elements in sorted order.

icon
Related questions
Question
Write a function that takes two sorted arrays as input and merges them into a single sorted
array. The function should return the merged array.
The input arrays are already sorted in ascending order, and they may have different lengths.
You can assume that both arrays contain only integers.
Example:
Input:
Array 1: [1, 3, 5, 7, 9]
Array 2: [2, 4, 6, 8, 10, 12]
Output:
Merged Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12]
Write a function `mergeSortedArrays that takes two sorted arrays as parameters and
returns a single merged array that contains all the elements in sorted order.
Transcribed Image Text:Write a function that takes two sorted arrays as input and merges them into a single sorted array. The function should return the merged array. The input arrays are already sorted in ascending order, and they may have different lengths. You can assume that both arrays contain only integers. Example: Input: Array 1: [1, 3, 5, 7, 9] Array 2: [2, 4, 6, 8, 10, 12] Output: Merged Array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12] Write a function `mergeSortedArrays that takes two sorted arrays as parameters and returns a single merged array that contains all the elements in sorted order.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer