GDP Labs interview question

Leetcode medium-easy, more of basic looping but in relatively large scope in interview