Google Interview Question

A grid Leetcode question, but I didn't make it.