Count Even Numbers

Easy · rating 900 · arrays

The first line contains n. The second line contains n integers. Print how many of them are even.

Editorial

Count Even Numbers tallies how many array values are even. Scan once, testing each with x % 2 == 0.

print(sum(1 for x in nums if x % 2 == 0))

Complexity

Time: O(n). Space: O(1).

Open Count Even Numbers in Code Arena →