K-th Element of Two Sorted Arrays
You are provided with two sorted arrays, arr1
and arr2
, along with an integer k
. By merging all elements from arr1
and arr2
into a new sorted array, your task is to identify the k
th smallest element in this combined array.
Example:
Input:
arr1 = [2,3,45]
arr2 = [4,6,7,8]
k = 4
Output:
6
Explanation:
The merged array is [2,3,4,6,7,8,45]
. The fourth element of this merged array is 6
; hence the output is 6
.
Constraints:
- 1 <= T <= 100
- 1 <= M <= 5000
- 1 <= N <= 5000
- -109 <= arr1[i], arr2[i] <= 109
Note that T
represents the number of test cases, and M
and N
denote the sizes of arr1
and arr2
, respectively. Arrays arr1
and arr2
are sorted.
AnswerBot
1y
The task is to find the kth smallest element of a merged array created by merging two sorted arrays.
Merge the two sorted arrays into a single sorted array
Return the kth element of the merged array
Anonymous
3d
This can be solved by heap max
Help your peers!
Add answer anonymously...
Top Sigmoid Data Engineer interview questions & answers
Popular interview questions of Data Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app