


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.
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’.
Return the 'kth' element of the combined sorted array.
You do not need to print anything; it has already been taken care of. Just implement the given function.
The key idea in solving this problem is to merge the 2 sorted arrays into a single sorted array and find its kth element.
The algorithm will be -
The key idea in solving this problem is to use the divide and conquer approach i.e binary search on both the arrays to find the ‘kth’ element.
The algorithm will be -
The binary search approach for solving this problem can be further optimised. Instead of dividing the array in blocks of n/2 and m/2 we can divide it in blocks of k/2.
The algorithm will be -