Values That Are Row Minima and Column Maxima

Quick Overview

Values That Are Row Minima and Column Maxima. In the matrix of distinct values, return all entries that are the minimum of their row and the maximum of their column.

Values That Are Row Minima and Column Maxima

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem In the matrix of distinct values, return all entries that are the minimum of their row and the maximum of their column. The source allows any output order. With globally distinct entries there can in fact be at most one such value. ```cpp class Solution { public: vector<int> luckyNumbers(vector<vector<int>>& matrix); }; ``` ### Examples **Example 1:** ```text Input: matrix = [[2,5],[7,9]] Output: [7] Explanation:7 is the second row's minimum and the first column's maximum. ``` **Example 2:** ```text Input: matrix = [[1,4],[3,2]] Output: [] Explanation: The row minima1 and2 are both below another value in their respective columns. ``` ### Constraints - The rectangular matrix has 1 to 50 rows and 1 to 50 columns. - Values are integers in `[1,100000]` and globally distinct. - Apply both the row-minimum and column-maximum tests to each candidate. ### Contract considerations All matrix values are distinct. Return every value passing both tests; the result may be empty. ```hint Read the boundary condition Check both required directions of comparison for each returned value. The distinct-value premise and the possibility of an empty result still apply. ``` ### Boundary reminders All matrix values are distinct. Return every value passing both tests; the result may be empty.

Overview: Values That Are Row Minima and Column Maxima. In the matrix of distinct values, return all entries that are the minimum of their row and the maximum of their column.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

In the matrix of distinct values, return all entries that are the minimum of their row and the maximum of their column. The source allows any output order. With globally distinct entries there can in fact be at most one such value.

class Solution {
public:
    vector<int> luckyNumbers(vector<vector<int>>& matrix);
};

Examples

Example 1:

Input: matrix = [[2,5],[7,9]]
Output: [7]
Explanation:7 is the second row's minimum and the first column's maximum.

Example 2:

Input: matrix = [[1,4],[3,2]]
Output: []
Explanation: The row minima1 and2 are both below another value in their respective columns.

Constraints

  • The rectangular matrix has 1 to 50 rows and 1 to 50 columns.
  • Values are integers in [1,100000] and globally distinct.
  • Apply both the row-minimum and column-maximum tests to each candidate.

Contract considerations

All matrix values are distinct. Return every value passing both tests; the result may be empty.

Boundary reminders

All matrix values are distinct. Return every value passing both tests; the result may be empty.