*This code describes how to find a lucky number in a matrix. *
const luckyNumber = (matrix)=>{
let num = []
for (let i = 0; i < matrix.length; i++) {
let arr = matrix[i];
let rowMax = Math.min(...arr);
let columnIndex = matrix[i].indexOf(rowMax);
let column = matrix.map((row) => row[columnIndex]);
let columnMax = Math.max(...column);
if (rowMax === columnMax) {
num.push(rowMax);
}
}
return num;
}
Top comments (0)