Google interview question

Basic algorithmic coding question, leetcode style