11. Count Even and Odd Numbers

EasyArrayArray

Given an integer array nums, return an array [even_count, odd_count] where:
- even_count = number of even integers in nums
- odd_count = number of odd integers in nums

Note: 0 is considered even.

Input: An integer array nums of length n.

Output: An array [even_count, odd_count].

Examples

Example 1
Input: [1,2,3,4,5]
Output: [2,3]
Explanation: Even: [2,4] → count=2. Odd: [1,3,5] → count=3. Return [2,3].
Example 2
Input: [2,4,6,8]
Output: [4,0]
Explanation: All even. even_count=4, odd_count=0. Return [4,0].
Example 3
Input: [1,3,5,7]
Output: [0,4]
Explanation: All odd. even_count=0, odd_count=4. Return [0,4].

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →