Lucky Numbers in a Matrix
Real-world version: Readings Lowest in Their Row and Highest in Their ColumnThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def lucky_numbers(matrix: list[list[int]]) -> list[int]:public List<Integer> luckyNumbers(int[][] matrix)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's