FastPrepK-th Element of Two Sorted Arrays
Problems/K-th Element of Two Sorted Arrays

K-th Element of Two Sorted Arrays

Flipkart logoFlipkart● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This exercise comes from a reported onsite problem-solving round. It asked for the k-th element of two sorted arrays, and required a logarithmic binary search. We chose the function signature, the exact limits, a one-based rank, and the examples. Our version is about 93% the same as the reported question.

Two integer arrays, first and second, are sorted in nondecreasing order. Return the k-th smallest value across both arrays, where k is one-based.

Your solution must run in O(log(min(first.length, second.length))) time and use O(1) auxiliary space.

Function

kthElement(first: int[], second: int[], k: int) → int

Examples

Example 1

first = [2,3,6,7,9]second = [1,4,8,10]k = 5return = 6

The merged order starts 1, 2, 3, 4, 6, so the fifth value is 6.

Example 2

first = []second = [-5,0,12]k = 2return = 0

When one array is empty, select directly from the other array.

Constraints

  • 0 <= first.length, second.length <= 100000
  • 1 <= first.length + second.length
  • -1000000000 <= first[i], second[i] <= 1000000000
  • Both arrays are sorted in nondecreasing order.
  • 1 <= k <= first.length + second.length

Source note: The source image is a source-neutral excerpt of the author-reported prompt.

More Flipkart interview questions

  • Zigzag Level-Order TraversalONSITE INTERVIEW · Seen Oct 2026
  • Minimized Total Idle TimeOA · Seen Dec 2025

Similar questions at other companies

  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Russian Doll EnvelopesGoogle · ONSITE INTERVIEWGoogle interview questions
  • Allocate Minimum PagesAmazon · ONSITE INTERVIEW
  • Minimum Processing Speed with Multiple RidersDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
  • Median of Two Sorted ArraysRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Median of Two Sorted ArraysMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Split Array Largest SumBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • Median of Two Sorted ArraysExpedia · ONSITE INTERVIEWExpedia interview questions
See Flipkart hiring insights
Saved
class Solution {
    public int kthElement(int[] first, int[] second, int k) {
      // Write your code here.
    }
}
Checking account…