Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4398 |

@sanjay05 | 3762 |

@mantu_singh | 3654 |

@gfgaccount | 3601 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 899 |

@akhileshkumar562002 | 862 |

@kanewilliamson123 | 854 |

@pradeeppatidar1999 | 852 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@smitabose7826 | 784 |

@wallflowe101 | 778 |

Complete Leaderboard |

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 = 5
Ar1[] = {1, 2, 4, 6, 10}
Ar2[] = {4, 5, 6, 9, 12}
**Output:** 11
**Explanation:** The merged array looks like
{1,2,4,4,**5,6,**6,9,10,12}. Sum of middle
elements is 11 (5 + 6).

**Example 2:**

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

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **findMidSum()** which takes **ar1, ar2** and **n **as input parameters and returns the sum of middle elements.

**Expected Time Complexity:** O(log N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{3}

1 <= Ar1[i] <= 10^{6}

1 <= Ar2[i] <= 10^{6}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Sum of Middle Elements of two sorted arrays

...