Toptal interview question

I cannot share. Just a middle level question from Leetcode.