PACT Pharma interview question

Easy problem from Leet code