Pergunta de entrevista da empresa Intel Corporation

question from leetcode, not hard