![]() |
VOOZH | about |
You are given an array arr[]. Your task is to count the number of even and odd elements. Return first odd count then even count.
Examples:
Input: arr = [2, 3, 4, 5, 6]
Output: 2 3
Explanation: There are two odds[3, 5] and three even[2, 4, 6] present in the array.
Input: arr = [22, 32, 42, 52, 62]
Output: 0 5
Explanation: All the elements are even.
Table of Content
2 3
We can also check if a number is odd or even by doing AND of 1 and that digit, if the result comes out to be 1 then the number is odd otherwise, it is even.
2 3
Time Complexity: O(n)
Auxiliary Space: O(1) because it is using constant space for variables