Find Cells That Are Their Row Minimum and Column Maximum
Last updated: November 29, 2026
Quick Overview
Given an m x n grid of distinct integers, return every value that is the smallest in its row and also the largest in its column.
0
0
0 solved
Given an m x n grid of distinct integers, return every value that is the smallest in its row and also the largest in its column.
A short Google phone screen question that rewards precomputation over nested rescans. The interviewer looks for the O(mn) two-pass solution and, ideally, the observation that at most one such cell can exist when values are distinct.
What the Interviewer Expects
- Precomputes row minima and column maxima in one or two passes
- Avoids rescanning a full row and column for every cell
- Returns values in a deterministic order
- Argues that distinct values allow at most one answer
- States O(mn) time and O(m + n) space
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
- Prove there is at most one such cell when all values are distinct.
- Values may repeat: what changes about uniqueness and the check?
- Find cells that are the row maximum and the column minimum instead.
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:
grid, m x n distinct ints. - Output: list of values
grid[r][c]withgrid[r][c] == min(row r)andgrid[r][c] == max(column c)....
High-Level Design
Compute row_min[r] for every row and col_max[c] for every column, then a cell qualifies exactly when its value equals both. That is two passes of O(mn) instead of the O(mn(m + n)) brute force.
Un...