Google interview question

Matrix based leetcode medium question.