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
2d
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...
Top Ola Cabs Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
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