I need an optimal way to iterate through the array
I know this a conceptual based site and is asking homework type questions is not appreciated. So before I ask for help, here is background about me: I am a competitive programmer, and I do it as my hobby.