Google Interview Question

a question from leetcode that was easy level