K-th Element of Two Sorted Arrays

Problem Statement

Problem Statement

You're given two sorted arrays 'arr1' and 'arr2' of size 'n' and 'm' respectively and an element 'k'.

Find the element that would be at the 'kth' position of the combined sorted array.

Position 'k' is given according to 1 - based indexing, but arrays 'arr1' and 'arr2' are using 0 - based indexing.

For Example :

Input: 'arr1' = [2, 3, 45], 'arr2' = [4, 6, 7, 8] and 'k' = 4
Output: 6
Explanation: The merged array will be [2, 3, 4, 6, 7, 8, 45]. The element at position '4' of this array is 6. Hence we return 6.

Detailed explanation ( Input/output format, Notes, Images )keyboard_arrow_down

Input Format :

The first line contains ‘n’ denoting the number of elements in ‘arr1’.

The second line contains ‘n’ space-separated integers denoting the elements of ‘arr1’.

The third line contains ‘m’ denoting the number of elements in ‘arr2’.

The fourth line contains ‘m’ space-separated integers denoting the elements of ‘arr2’.

The fifth line contains an integer ‘k’.

Output Format :

Note :

Sample Input 1:

Sample Output 1:

Explanation Of Sample Input 1 :

Sample Input 2:

Sample Output 2:

Explanation Of Sample Input 2 :

Constraints :

Expected Time Complexity :

Intuition

https://www.codingninjas.com/studio/problems/k-th-element-of-2-sorted-array_1164159?utm_source=striver&utm_medium=website&utm_campaign=a_zcoursetuf&leftPanelTab=0

https://www.youtube.com/watch?v=D1oDwWCq50g&ab_channel=takeUforward

Approach 1:

Approach 2:

Approach 3:

Approach 4:

Similar Problems

Last updated