![[Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix [Algorithm] Count Negative Integers in Row/Column-Wise Sorted Matrix](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
// Code goes here function countNegative (M, n, m) {
count = ;
i = ;
j = m - ; while (j >= && i < n) {
if (M[i][j] < ) {
count += (j+)
i += ;
} else {
j -= ;
}
} return count;
} const M = [
[-,-,-,],
[-,,,],
[,,,,]
]
console.log(countNegative(M, M.length, M[].length)) //