Pergunta de entrevista da empresa CIBC

Was asked leetcode easy question