Geeksforgeeks

Error

×

Leaderboard

Showing:

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

@Ibrahim Nash | 6420 |

@blackshadows | 6376 |

@mb1973 | 5594 |

@Quandray | 5231 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4510 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3412 |

Complete Leaderboard | |

Handle | Score |

@codersgroup18 | 783 |

@Manikanta punnam | 605 |

@sriramgoparaju99 | 586 |

@rdakka | 538 |

@praveenbgp6 | 529 |

@prankursharma31 | 518 |

@yashkaril4 | 517 |

@purohitmn02 | 467 |

@sonamnigam1999 | 443 |

@sonamkumari63928 | 441 |

@shubhamstudent5 | 433 |

Complete Leaderboard |

Given two sorted arrays **arr1** and **arr2** of size **M** and **N** respectively and an element **K**. The task is to find the element that would be at the k’th position of the final sorted array.

**Example 1:**

**Input:**
arr1[] = {2, 3, 6, 7, 9}
arr2[] = {1, 4, 8, 10}
k = 5
**Output:**
6
**Explanation:**
The final sorted array would be -
1, 2, 3, 4, 6, 7, 8, 9, 10
The 5th element of this array is 6.

**Input:**
arr1[] = {100, 112, 256, 349, 770}
arr2[] = {72, 86, 113, 119, 265, 445, 892}
k = 7
**Output:**
256
**Explanation:**
Final sorted array is - 72, 86, 100, 112,
113, 119, 256, 265, 349, 445, 770, 892
7th element of this array is 256.

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **kthElement()** which takes the arrays **arr1[]**, **arr2[]**, its size **N **and **M **respectively and an integer **K **as inputs and returns the element at the Kth position.

**Expected Time Complexity:** O(Log(N) + Log(M))

**Expected Auxiliary Space:** O(Log (N))

**Constraints:**

1 <= N, M <= 10^{6}

1 <= arr1_{i}, arr2_{i} <= 10^{6}

1 <= K <= N+M

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?

Yes
K-th element of two sorted Arrays

...