Toptal interview question

A hardened version hard question in leetcode