Yahoo interview question

Programming question, very similar to leetcode problems