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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

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
Staircase Search
Sorted Matrix
Two Pointers
Elimination Argument
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
  • 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 Problems
Sample Answer
Requirements
  • Input: table with rows ascending and columns ascending (non-strict), and target.
  • Output: True if any cell equals target.
  • 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...


Submit Your Answer
Markdown supported