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 kth 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
4mo
This can be solved by heap max
Help your peers!
Select
Add answer anonymously...

Sigmoid Data Engineer interview questions & answers

A Data Engineer was asked 9mo agoQ. How would you sort an array containing only 0s and 1s?
A Data Engineer was asked 9mo agoQ. Given a matrix, traverse and print its elements in a spiral manner.
A Data Engineer was asked 12mo agoQ. Given the head of a singly linked list, determine if the linked list has a cycle...read more

Popular interview questions of Data Engineer

A Data Engineer was asked 9mo agoQ1. Given a matrix, traverse and print its elements in a spiral manner.
A Data Engineer was asked 12mo agoQ2. Given the head of a singly linked list, determine if the linked list has a cycle...read more
A Data Engineer was asked Q3. Problem: Search In Rotated Sorted Array Given a sorted array that has been rotat...read more
Sigmoid Data Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits