All problems
1003EasyArrayMatrix

Readings Lowest in Their Row and Highest in Their Column

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1380Lucky Numbers in a Matrix

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A panel of readings is given as matrix, and no two readings anywhere on it are equal.

A reading is standout when it is the smallest in its own row and, at the same time, the largest in its own column.

Return every standout reading, listed in the order their rows appear.

Examples

Example 1

Input
matrix = [[2, 6, 9], [11, 14, 20], [24, 30, 35]]
Output
[24]

The reading 24 is the smallest of its row, whose other entries are 30 and 35, and the largest of its column, whose other entries are 2 and 11.

Example 2

Input
matrix = [[4, 12, 7], [19, 3, 18], [25, 21, 10]]
Output
[]

The row smallests are 4, 3 and 10, while the column largests are 25, 21 and 18. Nothing appears in both lists, so no reading stands out.

Example 3

Input
matrix = [[9, 4], [3, 1]]
Output
[4]

The reading 4 is smaller than the 9 beside it and larger than the 1 below it.

Constraints

  • 1 <= matrix.length <= 50
  • 1 <= matrix[i].length <= 50
  • 1 <= matrix[i][j] <= 10^5
  • No two readings on the panel are equal.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def lucky_numbers(matrix: list[list[int]]) -> list[int]:
Java
public List<Integer> luckyNumbers(int[][] matrix)
September 7
Apply