Find a Latency Value in a Table Sorted by Rows and Columns
Last updated: November 29, 2026
Quick Overview
Given an m x n table of request latencies where every row is sorted left to right and every column is sorted top to bottom, decide whether a target latency appears in the table.
0
0
0 solved
Given an m x n table of request latencies where every row is sorted left to right and every column is sorted top to bottom, decide whether a target latency appears in the table.
A compact Google phone screen problem about exploiting two sort orders at once. The interviewer wants the staircase walk from a corner and a clear argument for why each step safely discards a whole row or column.
What the Interviewer Expects
- Rejects the O(mn) scan and the per-row binary search as suboptimal
- Starts from the top-right (or bottom-left) corner
- Justifies why each comparison eliminates a row or a column
- Achieves O(m + n) time and O(1) space
- Handles empty tables and duplicates
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Count how many entries are less than or equal to the target.
- Return every position of the target if duplicates are allowed.
- Which approach wins when m is 10 and n is a million?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
tablewith rows ascending and columns ascending (non-strict), andtarget. - Output:
Trueif any cell equalstarget. - Rows sorted alone is not enough for one flat binary search; the t...
High-Level Design
Start at the top-right cell. Everything to its left in that row is smaller and everything below it in that column is larger. If the cell is greater than the target, the whole column below is even larg...