Ninja and Sorted Array Merging Problem
Ninja is tasked with merging two given sorted integer arrays ARR1
and ARR2
of sizes 'M' and 'N', respectively, such that the merged result is a single sorted array within ARR1
. Assume ARR1
has a size of 'M' + 'N', allowing it to accommodate all the elements of ARR2
as well.
Example:
Input:
ARR1 = [3, 6, 9, 0, 0]
ARR2 = [4, 10]
Output:
ARR1 = [3, 4, 6, 9, 10]
Input:
The input format is as follows:
The first line contains an integer ‘T’, the number of test cases. Each test case consists of:
- A line containing two space-separated integers ‘M’ and ‘N’, the sizes of ‘ARR1’ and 'ARR2'.
- A line with 'M' integers followed by 'N' zeros (representing 'ARR1' with placeholders for 'ARR2').
- A line with ‘N’ integers representing 'ARR2'.
Output:
For each test case, the function must output the merged array ARR1
.
Constraints:
- 1 <= T <= 100
- 1 <= M, N <= 5000
- 1 <= ARR1[i], ARR2[i] <= 100000
- Time limit: 1 second
Note:
You are not required to print anything; handle the logic within the provided function.
Be the first one to answer
Add answer anonymously...
>
Mahindra Logistics SDET-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

