Write an algorithm which finds out the elements which are largest in a row and smallest in a column in a matrix.
Input
The first line of input consists of two space-separated integers- matrix_row and matrix_col, representing the number of rows in the matrix (N) and the number of columns in the matrix (M), respectively.
The next M lines consist of N space-separated integers representing the elements of the matrix.
Output
Print a number which is largest in a row and smallest in a column in the given matrix. If no element is found print '-1'.
Note
Each number in the matrix is a non-negative integer.
Examples
01 · Example 1
matrix = [[1, 2], [3, 4]] return = 2
The number 2 at index (0,1) is the largest in its row and smallest in its column.
So, the output is 2.
Constraints
1 ≤ N, M ≤ 1000More Cisco problems
- Collect CoinsSeen Jun 2025
- FizzBuzz ProblemSeen May 2025
- Find Largest Sum Contiguous SubarraySeen May 2025
- Find Largest Sum of Continuous SequenceSeen May 2025
- Find Palindrome Sub-stringSeen May 2025
- Flight Path Package DropSeen May 2025
- Count Numbers with Digit SumSeen Mar 2025
- Maximum Chocolates from Jars (L.C. 198 :)Seen Mar 2025
public int findElementLargestInRowSmallestInColumn(int[][] matrix) {
// write your code here
}
matrix[[1, 2], [3, 4]]
expected2
sign in to submit