Count Even Numbers
easySave
ArrayCounting
Given an array of integers, return the count of even numbers in the array.
Example 1
Input
[ 2, 5, 6, 3, 8 ]
Output
3
Explanation. The even numbers in the array are 2, 6, and 8. Therefore, the count is 3.
Example 2
Input
[ 7, 1, 9, 17 ]
Output
0
Explanation. There are no even numbers in this array.
Example 3
Input
[]
Output
0
Explanation. The array is empty, so the count of even numbers is 0.
Example 4
Input
[ -2, 4, 0, 18 ]
Output
4
Explanation. Negative, zero and positive even numbers are present (-2, 0, 4, 18).
Follow-up: Can you solve this problem in linear time complexity and constant space complexity?
Constraints:
- The input array can have numbers ranging from negative to positive integers.\n- The array may be empty.
- Views
- 2