Dsa
Arrays
Easy
Merge Sorted Arrays
You are given two sorted arrays of integers. Write a program that merges these two arrays into a single sorted array without using any additional array for storage. The merged array should be printed as a single line of space-separated integers.
Input format:
- The first line contains an integer n, the length of the first array.
- The second line contains n space-separated integers (the first array).
- The third line contains an integer m, the length of the second array.
- The fourth line contains m space-separated integers (the second array).
Output format:
- A single line containing the merged sorted array.
Example:
Input:
3
1 3 5
4
2 4 6 8
Output:
1 2 3 4 5 6 8
Key concepts
arrayssorting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now