RetailMeNot interview question

Algorithm.