Toptal Interview Question

To solve the code problem