230k views
3 votes
write an algo which finds out the elements which are largest in a row and smallest in a column in a matrix.

1 Answer

4 votes

Final answer:

To find the elements which are largest in a row and smallest in a column in a matrix, you can follow these steps: Declare two arrays, one for the row maximums and another for the column minimums; Iterate through each row to find the maximum element in each row; Iterate through each column to find the minimum element in each column; Loop through the row maximums and column minimums to find the common elements and print or store them.

Step-by-step explanation:

To find the elements which are largest in a row and smallest in a column in a matrix, you can follow these steps:

  1. Declare two arrays, one to store the maximum element in each row and another to store the minimum element in each column.
  2. Iterate through each row of the matrix:
  • Set the maximum value in the row as the first element.
  • Compare each element in the row with the current maximum value and update it if a larger value is found.
Iterate through each column of the matrix:
  • Set the minimum value in the column as the first element.
  • Compare each element in the column with the current minimum value and update it if a smaller value is found.
Loop through the row maximum array and column minimum array to find the common elements, i.e., elements that are both maximum in their row and minimum in their column.Print or store the common elements as required.

User Rohit Agrawal
by
8.2k points