Lucky Numbers in a Matrix

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

30:00

Lucky Numbers in a Matrix
easy
Free written solution
Topics
Companies

Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order.

A lucky number is an element of the matrix such that it is the minimum element in its row and the maximum element in its column.

Example 1:
Input: {"matrix":[[3,7,8],[9,11,13],[15,16,17]]}
Output: [15]
Constraints:
  • m=matrix.lengthm = \text{matrix.length}, n=matrix[i].lengthn = \text{matrix[i].length}

  • 1≤n,m≤501 \leq n, m \leq 50

  • 1≤matrix[i][j]≤1051 \leq \text{matrix[i][j]} \leq 10^5

  • All elements in the matrix are distinct.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"matrix":[[3,7,8],[9,11,13],[15,16,17]]}

A lucky number is the smallest in its row and the largest in its column. With distinct values there can be at most one, and it must equal both the largest row minimum and the smallest column maximum.

row minimum

column maximum

both

0

3
7
8

1

9
11
13

2

15
16
17

0

1

2

max of row mins -

?

min of col maxes -
Variables
VariableValue
m3
n3
DepthFunction Call
Stack empty
0/8