Pergunta de entrevista da empresa UBS

leetcode easy medium question that wa bit difficult