Easy
Count Even Numbers in an Array
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Arrays and Strings
Description
Given an array of integers, return how many elements are even.
An integer is even if it is divisible by 2 with no remainder. Zero and negative even integers are also considered even.
For example, [1, 2, 3, 4, 6] contains three even elements.
Implement countEven(nums) to return the number of even elements.
Constraints
1 <= nums.length <= 1000 -1000000 <= nums[i] <= 1000000
Sample cases
3Sample 1
Input
nums = [1,2,3,4,6]
Expected output
3
Sample 2
Input
nums = [1,3,5]
Expected output
0
Skills and languages
Concepts
- Divisibility and Remainders
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer