Median of sorted arrays

how can i merge two sorted arrays into the third array.

to merge two sorted arrays into the third array, what you can do is have two pointers say i and j for arr1 and arr2 respectively,initialized with 0, i.e. pointing to first element

  • Create an array arr3[] of size n1 + n2.
  • Simultaneously traverse arr1[] and arr2[].
  • Pick smaller of current elements in arr1[] and arr2[],i.e min(arr1[i],arr2[j]) copy this smaller element to next position in arr3[] and move ahead in arr3[] and the array whose element is picked(eg , i++ if arr[i] is smaller than arr[j] and vice versa).
  • If there are remaining elements in arr1[] or arr2[], copy them also in arr3[]

refer code for better understanding :-

In case of any doubt feel free to ask :slight_smile:
Mark your doubt as RESOLVED if you got the answer