Reported July 2026
NatWestarray

Sum Elements at Even Indices

Reported by candidates from NatWest's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live NatWest OA. Under 2s to a working solution.
Founder's read

Strip away the wrapper and this NatWest OA, reported in July 2026, is a single loop with a stride of two. The task: given an integer array, return the sum of elements at even indices, zero-based. That's it. If you're staring at the invite expecting something nasty, relax a little. It's an array problem, and the only way to lose is by overthinking it or fumbling an off-by-one. If you blank anyway, StealthCoder runs invisibly on your desktop during the live assessment and hands you the answer as a safety net. You probably won't need it here.

The problem

You are given an integer array nums. Return the sum of the elements at even indices of the array.
Use standard zero-based indexing.

Function
sumEvenIndices(nums: int[]) → int

Examples
Example 1
nums = [4,1,7,3,2]
return = 13
The even indices are 0, 2, and 4, so the sum is 4 + 7 + 2 = 13.
The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The whole trick is the index parity. Start at i = 0, step by 2, add nums[i] to a running total, stop when i reaches the length. No hash map, no sorting, no two pointers. One pass, O(n) time, O(1) space. The common pitfalls are small but real. People confuse even indices with even values and sum the wrong thing. Others go one-based and grab positions 1, 3, 5. Check the example: [4,1,7,3,2] gives indices 0, 2, 4, so 4 + 7 + 2 = 13. Also handle an empty array by returning 0, which the loop does naturally. Watch for negative numbers, since they just subtract and need no special case. Overflow is unlikely, but if the language has fixed-width ints, think about it for a second. Write it, run the sample, move on. If your head goes blank under the clock, StealthCoder is the hedge on the live OA, but this one is mostly muscle memory.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Sum Elements at Even Indices cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass NatWest's OA.

NatWest reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sum Elements at Even Indices FAQ

How hard is the NatWest Sum Elements at Even Indices question really?+

It's about as easy as OA coding gets. One loop, one accumulator, no tricky data structures. The difficulty is purely not making a careless mistake like using values instead of indices. Solve it in a couple of minutes and spend the leftover time on any harder questions in the same assessment.

What's the trick to solving it?+

Loop with i starting at 0 and incrementing by 2, adding nums[i] each time. That skips every odd index for free. You can also loop normally and check i % 2 == 0. Both are O(n). The stride-by-two version is cleaner and avoids a branch.

Does zero-based indexing change the answer?+

Yes, completely. The problem says zero-based, so index 0 counts as even and is included. In [4,1,7,3,2] that means 4, 7, and 2 are summed to get 13. If you accidentally go one-based, you'd get 1 + 3 = 4, which is wrong.

What edge cases should I test?+

Test an empty array, which should return 0. Test a single element, which returns that element. Test negative numbers, which just reduce the sum. Test an even-length array to confirm the last odd index is skipped. Those four cover nearly every way this can break.

How do I prepare in 48 hours for an OA like this?+

Don't grind hard problems for this one. Practice writing basic array loops in your chosen language until stride loops, modulo checks, and accumulators feel automatic. Then review a few easy array and prefix-sum problems. Speed and accuracy on simple questions matters because they usually come bundled with harder ones.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with NatWest.

OA at NatWest?
Invisible during screen share
Get it