Pergunta de entrevista da empresa CGI

LeetCode algorithm question solved using JavaScript.