CoverMyMeds interview question

Hacker rank problem mostly. how well you optimise them