FastPrepK-th Smallest Value in a Sorted Matrix
Problems/K-th Smallest Value in a Sorted Matrix

K-th Smallest Value in a Sorted Matrix

PhonePe logoPhonePe● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a PhonePe onsite interview. The report names the standard task of picking from a sorted matrix. We added the function interface and clear limits. The main task stays the same. Our version is about 95% the same as the reported question.

Given a non-empty rectangular integer matrix whose rows and columns are each sorted in nondecreasing order, return the k-th smallest matrix value when all values are counted with multiplicity.

Function

kthSmallest(matrix: int[][], k: int) → int

Examples

Example 1

matrix = [[1,5,9],[10,11,13],[12,13,15]]k = 8return = 13
matrix
012015911011132121315

The sorted values place 13 in position 8.

Example 2

matrix = [[-5]]k = 1return = -5
matrix
00-5

The only value is the first smallest.

Constraints

  • 1 <= matrix.length, matrix[i].length <= 300
  • Every row has the same positive length.
  • Rows and columns are sorted in nondecreasing order.
  • 1 <= k <= rows * columns
  • Matrix values are between -10^9 and 10^9.

Source note: Interview prompt excerpt preserved as source evidence.

More PhonePe interview questions

  • Evaluate DivisionONSITE INTERVIEW · Seen Oct 2026
  • Identify Two Failing Tests From an Oracle TranscriptONSITE INTERVIEW · Seen Sep 2026
  • Count Bowl SubarraysONSITE INTERVIEW · Seen Jul 2026
  • Reconstruct ItineraryONSITE INTERVIEW · Seen Jul 2026
  • Constrained Jump SequencesOA · Seen Aug 2026
  • Maximum Payout with Context SwitchesOA · Seen Aug 2026
  • Substrings Without a Target SubsequenceOA · Seen Aug 2026
  • Luna and the Colorful SocksOA · Seen Jul 2026

Similar questions at other companies

  • Find the Safest Path in a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Kth Smallest Value in a Row- and Column-Sorted MatrixOpenAI · PHONE SCREENOpenAI interview questions
  • Swim in Rising WaterUiPath · PHONE SCREEN
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Staircase Search In A Sorted MatrixGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Minimum-Weight Top-to-Bottom Grid PathGoogle · ONSITE INTERVIEWGoogle interview questions
  • Trip Booking with the Earliest Free DriverRippling · ONSITE INTERVIEWRippling interview questions
  • Staircase Search In A Sorted MatrixMotive · ONSITE INTERVIEWMotive interview questions
  • Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
All PhonePe interview questionsSee PhonePe hiring insights
Saved
class Solution {
    public int kthSmallest(int[][] matrix, int k) {
        // Write your code here.
    }

}
Checking account…