Merge Two Sorted Arrays Problem Statement
Given two sorted integer arrays ARR1
and ARR2
of size M and N, respectively, merge them into ARR1
as one sorted array. Assume that ARR1
has a size of M + N to hold all elements of ARR2
.
Input:
The first line contains an integer T representing the number of test cases. Each test case contains:
- Two space-separated integers M and N.
- A line with M integers followed by N zeros in ARR1.
- A line with N integers in ARR2.
Output:
For each test case, return the merged ARR1
as one sorted array.
Example:
Input:
ARR1 = [3, 6, 9, 0, 0]
ARR2 = [4, 10]
Output:
ARR1 = [3, 4, 6, 9, 10]
Constraints:
- 1 <= T <= 100
- 1 <= M, N <= 5000
- 1 <= ARR1[i], ARR2[i] <= 100000
Time Limit: 1 second
Note:
Ensure the function implementation handles the merging, output has already been managed.
Be the first one to answer
Add answer anonymously...
Top Freshworks Graduate Trainee interview questions & answers
Popular interview questions of Graduate Trainee
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app