Google interview question

Similar to Rotten oranges leetcode