← 返回 cisco 的题目列表Row Maximum / Column Minimum
类型:qbank
Find the matrix element that is largest in its row and smallest in its column; print `-1` if no such element exists.
Requirements
Input line 1 contains matrix_row and matrix_col.
The next lines contain the matrix elements.
Print a number that is largest in its row and smallest in its column.
If no element exists, print -1.
Constraints shown: 1 <= N, M <= 1000.
Each matrix value is a non-negative integer.
Examples
Input:
2 2
1 2
3 4
Output:
2
Explanation: 2 at index (0,1) is the largest in its row and smallest in its column.
Notes
Precompute row maxima and column minima, then scan for intersections.