Saddle Point Finder - Problem
A saddle point in a matrix is an element that is simultaneously the minimum in its row and the maximum in its column.
Given a 2D matrix, find all saddle points and return their coordinates as an array of [row, col] pairs.
Note: If no saddle points exist, return an empty array. Matrix elements can be positive, negative, or zero.
Input & Output
Example 1 — Matrix with One Saddle Point
$
Input:
matrix = [[1,7,3],[9,11,5],[4,3,2]]
›
Output:
[[2,2]]
💡 Note:
Element at [2,2] is 2. It's the minimum in row 2: [4,3,2] and maximum in column 2: [3,5,2]. Therefore, it's a saddle point.
Example 2 — Matrix with No Saddle Points
$
Input:
matrix = [[1,2],[3,4]]
›
Output:
[]
💡 Note:
No element satisfies both conditions. Element 1 is row min but not column max, element 4 is column max but not row min.
Example 3 — Single Element Matrix
$
Input:
matrix = [[5]]
›
Output:
[[0,0]]
💡 Note:
Single element 5 is both minimum in its row and maximum in its column by definition.
Constraints
- 1 ≤ m, n ≤ 300
- -104 ≤ matrix[i][j] ≤ 104
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code