Sum Elements at Even Indices
Updated
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[]) → 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.
More NatWest Group Online Assessment questions
Similar questions at other companies
- Missing IntervalsIBM · OAIBM interview questions
- Total Cost Against the Lowest Earlier PricePayPal · OAPayPal interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Count Valid Square PairsAuxoAI · OA
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Two SumAmazon · OA · PHONE SCREEN
- Competition Winner and Runner-Up (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Server InvestmentRippling · OARippling interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions