Pergunta de entrevista da empresa Twilio

Asked to solve a dsa problem in hackerrank.