Check Whether a Latency Value Exists in a Sorted Grid
Last updated: November 29, 2026
Quick Overview
A grid has every row sorted left to right and every column sorted top to bottom. Return whether a target value is present.
Meta
November 29, 20260
0
0 solved
A grid has every row sorted left to right and every column sorted top to bottom. Return whether a target value is present.
Fits a Meta phone screen as a fast question on exploiting structure, framed as a latency percentile table sorted by region and by hour. The interviewer checks that you find the linear staircase walk and can justify why each step eliminates a whole row or column.
What the Interviewer Expects
- Start at the top-right or bottom-left corner
- Explain why each comparison discards a row or a column
- Achieve O(R + C) time
- Compare with binary searching each row
- Handle empty rows
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 values are less than or equal to the target.
- What if the whole grid were sorted in row-major order?
- Can you do better than O(R + C) in the worst case?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Grid up to 300 x 300 with rows and columns sorted ascending.
- Return True if the target exists....
High-Level Design
At the top-right corner, the value is the largest in its row and the smallest in its column. If it is greater than the target, nothing below it in that column can match, so move left. If smaller, noth...