Merge 2 unsorted arrays into a sorted array

 Given 2 unsorted arrays, combine both of them such that the resultant array is sorted.

Print the resultant array.

Input Format

  1. First line contains size of first array
  2. Followed by elements of first array
  3. Following line contains size of 2nd array
  4. Followed by elements of the 2nd array

Output Format

Print the elements of the merged array on a single line

Example Input:

5
2 8 9 0 1
3
3 2 1

Output:


0 1 1 2 2 3 8 9


Solution:


n1=int(input())

a1=list(map(int,input().split()))

n2=int(input())

a2=list(map(int,input().split()))

a2=a1+a2  #merge two arrays

a2.sort()

for i in range(len(a2)):

    print(a2[i],end=" ")





Comments

Popular posts from this blog

Efficient Janitor

Right Arrow Pattern

X Pattern