Pergunta de entrevista da empresa IXL Learning

One medium leetcode question with follow up.