Pergunta de entrevista da empresa SPARC

Explain your logic for the HackerRank problem and what you would do differently in hindsight.