Google interview question

It is like a leetcode question