JSFiddle - React, Tailwind, and code Playground
JavaScript
const countLiveServers = (inp) => {
const rows = Array(inp.length).fill(0);
const cols = Array(inp[0].length).fill(0);
for (let i = 0; i < inp.length; i++) {
for (let j = 0; j < inp[0].length; j++) {
if (inp[i][j]) {
rows[i]++;
cols[j]++;
}
}
}
let liveServerCount = 0;
for (let i = 0; i < inp.length; i++) {
for (let j = 0; j < inp[0].length; j++) {
if (inp[i][j] && (rows[i] > 1 || cols[j] > 1)) {
liveServerCount++;
}
}
}
return liveServerCount;
};
console.log(countLiveServers([[1,0],[1,1]])); // 3