Python BasicsEasy

Counting even and odd elements in an array

Detailed guide and Python implementation for the 'Counting even and odd elements in an array' problem.

Problem Statement

Easy

Write a function count_even_odd(arr) that takes a list of integers arr and returns a tuple (even_count, odd_count) representing the number of even and odd elements in the array.

Constraints
  • 0 <= len(arr) <= 10^5
  • -10^9 <= arr[i] <= 10^9

Examples

Example 1
Input
arr = [1, 2, 3, 4, 5, 6]
Output
(3, 3)
Explanation

Even: 2, 4, 6 (count=3). Odd: 1, 3, 5 (count=3).

Example 2
Input
arr = [2, 4, 6, 8]
Output
(4, 0)
Explanation

All elements are even.

Example 3
Input
arr = [1, 3, 5]
Output
(0, 3)
Explanation

All elements are odd.

Need a Hint?
Consider using Arrays-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.