Google Interview Question

it was similar to leetcode