58. Lucky Number in a Matrix

EasyArrayArray

Given an m x n matrix of distinct numbers, return all lucky numbers in any order. A lucky number is an element that is the minimum of its row and the maximum of its column.

Input: A 2D array matrix of size m x n with distinct values.

Output: List of lucky numbers (can be empty).

Examples

Example 1
Input: [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
Explanation: 15 is min of row 2 (min=15) and max of col 0 (max=15). Lucky!
Example 2
Input: [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output: [12]
Explanation: 12 is min of row 2 (min=12) and max of col 3 (max=12).
Example 3
Input: [[7,8],[1,2]]
Output: [7]
Explanation: 7 is min of row 0 and max of col 0.

Constraints

Asked by

OracleAmazon
Solve this problem in the editor →