Toptal interview question

Be prepared with your algorithms