Kth Smallest Salary in a Row and Column Sorted Matrix

Last updated: November 29, 2026

Quick Overview

Salary data is aggregated into an n by n matrix where every row and every column is sorted ascending (for example by seniority and by region tier). Return the kth smallest value in the matrix.

LinkedIn
Coding & Algorithms
Data Engineer
LinkedIn
November 29, 2026
Data Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Salary data is aggregated into an n by n matrix where every row and every column is sorted ascending (for example by seniority and by region tier). Return the kth smallest value in the matrix.

LinkedIn Salary insights rely on percentile queries over aggregated grids. The interviewer checks whether you exploit the double sortedness, either with a heap over rows or binary search on value with a staircase count, and can compare them.

What the Interviewer Expects
  • Rejects flattening and sorting as O(n^2 log n)
  • Offers the min-heap over row heads in O(k log n)
  • Implements binary search on value with an O(n) staircase count
  • Explains why the search converges on a value that is in the matrix
  • Handles duplicates and k at either extreme
Key Topics to Cover
binary search on value
sorted matrix
staircase search
heaps
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Which approach wins when k is tiny versus near n^2?
  • How would you get the median of a non-square m by n matrix?
  • How do you count values less than or equal to x in O(n)?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: square matrix with rows and columns non-decreasing; 1 <= k <= n^2. Output: the kth smallest counting duplicates. Values may be large or negative integers....

High-Level Design

Binary search on the value range [matrix[0][0], matrix[-1][-1]]. For a candidate x, count entries <= x with a staircase walk from the bottom-left: if the cell is <= x, the whole column above it ...


Submit Your Answer
Markdown supported