Toptal Interview Question

Code this in 20 minutes