New York Times interview question

A simple coding exercise, sub-easy Leetcode difficulty