Problem · Array
Sum Elements at Even Indices
Learn this problemProblem 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[]) → intExamples
Example 1
nums = [4,1,7,3,2]return = 13The 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.