Google interview question

matrix mapping problem (med leetcode)