ShopBack interview question

Describe solution and time complexity