Meta interview question

Leetcode medium question about matrix