Google interview question

leetcode hard was unexpected and very difficult