K-th Element of 2 Sorted Array — Asked in Flipkart and Microsoft Interview


Problem Statement :
You are given two sorted arrays/list ‘arr1’ and ‘arr2’ and an integer k. You create a new sorted array by merging all the elements from ‘arr1’ and ‘arr2’. Your task is to find the kth smallest element of the merged array.
Sample Input:
arr1 = [2,3,45]arr2 = [4,6,7,8]k = 4
Sample Output:
6
Explanation of Sample Test Case:
The merged array will be : [2,3,4,6,7,8,45]
The fourth element of this array will be 6 hence we return 6.
Approach :
Time Complexity : O(log k)
Space Complexity : O(1)