Google interview question

Leetcoding as usual. Nothing too difficult.