Toptal interview question

Code this in 20 minutes