Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Sort the cells by value and process them in increasing order.
The rank of a cell is the maximum rank in its row and column plus one.
Handle the equal cells by treating them as components using a union-find data structure.