Ninja and Sorted Arrays Problem
You are given two sorted integer arrays, ARR1
and ARR2
, with sizes M
and N
, respectively. Merge these arrays into ARR1
as a single sorted array. Assume ARR1
has a size equal to M + N
, with enough space to include all elements of ARR2
.
Input:
Two sorted integer arrays ARR1 and ARR2, where:
‘ARR1’ = [3, 6, 9, 0, 0]
‘ARR2’ = [4, 10]
Output:
‘ARR1’ = [3, 4, 6, 9, 10]
Example
For example, after merging ARR1 and ARR2, ARR1 would look like this:
‘ARR1’ = [3, 6, 9, 0, 0]
‘ARR2’ = [4, 10]
Result after merging: ‘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:
You do not need to print anything. Implement the function as specified.

AnswerBot
4mo
Merge two sorted arrays into one sorted array in place.
Iterate from the end of both arrays and compare elements, placing the larger element at the end of ARR1
Continue this process until all elements f...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 2mo agoQ1. What is the optimized approach to calculate the sum of arrays?
A Software Developer Intern was asked Q2. Ninja and Sorted Arrays Problem You are given two sorted integer arrays, ARR1 an...read more
A Software Developer Intern was asked Q3. Game of Dominoes Problem Statement Rafiq loves to play with piles of dominoes, e...read more
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

