
function deleteGreatestValue(grid: number[][]): number {
let sum = 0
while(grid[0].length) {
let rowMax = -Infinity
for(let row = 0; row < grid.length; row++) {
const colMax = Math.max(...grid[row])
const maxIdx = grid[row].indexOf(colMax)
grid[row].splice(maxIdx, 1)
rowMax = Math.max(rowMax, colMax)
}
sum += rowMax
}
return sum
};