I need help troubleshooting my code that's supposed to calculate the sum of elements at odd positions in an array. I'm getting a wrong answer from AtCoder, and I'm not sure what I'm doing wrong. Here's a link to my submission: [AtCoder Submission](https://atcoder.jp/contests/abc403/submissions/65401113). Can anyone point out the issue?
3 Answers
Starting at i = 0 and incrementing by 2 will lead to summing the even-indexed values. Also, consider requesting the size of the array first and only creating an array with that number of elements to avoid wasting memory.
It looks like you might be adding even values instead of the odd-indexed ones. Remember, in programming, counting often starts from zero. If you're summing at indices 1, 3, 5, etc., you need to start your loop at i = 1 instead of i = 0.
The phrasing of the question is crucial. Since arrays are typically zero-based, index 0 is actually even. So, you should start at index 1 and then increment by 2. This way you’ll correctly target the odd indexed values like 1, 3, 5, etc.
The statement does suggest starting at index 0. I'm confused about how that fits into summing odd indices.
But the example mentions starting at index 0 and then adding +2 for subsequent values. Could there be a misunderstanding in how the example was phrased?