# Given 2 sorted arrays Ar1 and Ar2 of size N each. Merge the given arrays and find the sum of the two middle elements of the merged array.

Given 2 sorted arrays Ar1 and Ar2 of size N each. Merge the given arrays and find the sum of the two middle elements of the merged array.

Example 1:

`Input:N = 5Ar1[] = {1, 2, 4, 6, 10}Ar2[] = {4, 5, 6, 9, 12}Output: 11Explanation: The merged array looks like{1,2,4,4,5,6,6,9,10,12}. Sum of middleelements is 11 (5 + 6).`

Example 2:

`Input:N = 5Ar1[] = {1, 12, 15, 26, 38}Ar2[] = {2, 13, 17, 30, 45}Output: 32Explanation: The merged array looks like{1, 2, 12, 13, 15, 17, 26, 30, 38, 45} sum of middle elements is 32 (15 + 17).`

`//Given 2 sorted arrays Ar1 and Ar2 of size N each. Merge the given arrays and find the sum of the two middle elements of the merged array.func sumOfSortedArray(Ar1:[Int], Ar2:[Int],N:Int)->Int{var newArray = [Int]()newArray.append(contentsOf: Ar1)newArray.append(contentsOf: Ar2)newArray = newArray.sorted()//this is how we can get middle index by total of both array divided by 2 and need to minus 1 because array always start with 0 not 1.let middleElementIndex = ((N+N)/2) - 1let sum = newArray[middleElementIndex] + newArray[middleElementIndex + 1]print(sum)return sum}`