SmartNews interview question

Coding interview: A Leetcode Medium problem.