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

Anonymous
5mo
// Online Javascript Editor for free // Write, Edit and Run your Javascript code using JS Online Compiler a = [1,2 ,4, 7,9, 11, 19] b = [4,7,8,9,10,11] c = [] j=0 i=0 k = a.length + b.length - 1 while...read more
Anonymous
6mo
Agar kisi ko job ki jarurat ho to contact me 9922981768 part time work (office) Monthly Income starting 17 se 18 hajar
vishal jain
2y

// Online Javascript Editor for free

// Write, Edit and Run your Javascript code using JS Online Compiler

a = [1,2 ,4, 7,9, 11, 19]

b = [4,7,8,9,10,11]

c = []

j=0

i=0

k = a.length + b.length - 1

wh...read more

Select
Add answer anonymously...

Rakuten Software Developer interview questions & answers

A Software Developer was asked Q. What is polymorphism in Java?
A Software Developer was asked Q. Can you explain method overriding in Java?
A Software Developer was asked Q. What is the JVM?

Popular interview questions of Software Developer

A Software Developer was asked Q1. What is polymorphism in Java?
A Software Developer was asked Q2. Can you explain method overriding in Java?
A Software Developer was asked Q3. What is the JVM?
Rakuten Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits