SPARC Interview Question

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