G-Research interview question

Solve a matrix related coding challenge.