Microsoft interview question

Leetcode medium question related to matrices