
Asked in Spinny
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.

AnswerBot
4mo
Merge two sorted arrays into one sorted array in place.
Iterate from the end of both arrays and compare elements to merge in place
Use two pointers to keep track of the current position in each array
Han...read more
Help your peers!
Add answer anonymously...
Top Software Engineer Interview Questions Asked at Spinny
Q. Given n non-negative integers representing an elevation map where the width of e...read more
Q. Can you provide a low-level design of a hotel management system?
Q. Count Ways to Reach the Nth Stair Given a number of stairs, starting from the 0t...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for Spinny Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 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

