Google Interview Question

leetcode style question, whiteboard coding pretty much