Problem · Array

Sum Elements at Even Indices

Learn this problem
EasyNatWest GroupOA

Problem statement

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.

More NatWest Group problems

drafts saved locally
public int sumEvenIndices(int[] nums) {
  // write your code here
}
nums[4,1,7,3,2]
expected13
checking account