Back Market interview question

I had a Leetcode hard question