Row With Maximum Ones
EasyArrayMatrix
Solution
export function rowAndMaximumOnes(mat: number[][]): number[] {
function countOnes(row: number[]) {
return row.reduce((prev, num) => (num === 1 ? prev + 1 : prev), 0);
}
let rowIndex = -1;
let maxOneCount = -1;
mat.forEach((row, i) => {
const oneCount = countOnes(row);
if (maxOneCount < oneCount) {
rowIndex = i;
maxOneCount = oneCount;
}
});
return [rowIndex, maxOneCount];
}