Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Even Elements in Array

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Even Elements in Array. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Add the even elements in an array.

Implement sum_even_elements(nums), which accepts an array of integers and returns the sum of every even element. Return 0 when the array is empty or contains no even values.

Input: nums, a list of integers.

Output: An integer representing the sum of the even elements.

Example: nums = [1, 4, 7, 10] returns 14 because 4 + 10 = 14.

Constraints

  • 0 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • All elements are integers

Function Signature

def sum_even_elements(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output