K-th Smallest Value in a Sorted Matrix
Updated
Problem statement
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) → intExamples
Example 1
matrix = [[1,5,9],[10,11,13],[12,13,15]]k = 8return = 13The sorted values place 13 in position 8.
Example 2
matrix = [[-5]]k = 1return = -5The 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^9and10^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