Lucky Numbers in a Matrix
EasyMatrixsimulation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an m x n matrix of **distinct** integers. An element is *lucky* if it is the smallest value in its row and, at the same time, the largest value in its column.
Return all lucky numbers in **ascending order**. Return an empty array if there are none.
Examples
Input: matrix = [[3,7,8],[9,11,13],[15,16,17]]
Output: [15]
15 is the minimum of row 2 and the maximum of column 0.
Input: matrix = [[1,10,4,2],[9,3,8,7],[15,16,17,12]]
Output: [12]
12 is the minimum of its row and the maximum of column 3.
Input: matrix = [[7,8],[1,2]]
Output: [7]
7 is smallest in row 0 and largest in column 0.
Constraints
- m == matrix.length, n == matrix[i].length
- 1 <= m, n <= 50
- 1 <= matrix[i][j] <= 10^5
- All values in the matrix are distinct
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.