Google interview question

I received a Leetcode style question.