Google interview question

Look on leetcode for similar problems