Google interview question

leetcode style question, whiteboard coding pretty much