Count of odd numbers in array

Beginner Problems Basic Arrays Easy
  • Here's a fun fact: this problem is a basic exercise in data analytics, which is a massive part of the software industry
  • Almost all major companies - like Facebook, Google, Amazon - use data analytics to make informed decisions
  • This task is similar to finding specific patterns in the data, such as user habits or preferences
  • It's like asking, "how many users made purchases at odd-numbered hours?" or "how many users have spent an odd amount of money on our platform?" Understanding these patterns helps companies enhance their user experiences and profitability

Given an array of n elements. The task is to return the count of the number of odd numbers in the array.

Examples:

Input: n=5, array = [1,2,3,4,5]


Output: 3


Explanation: The three odd elements are (1,3,5).

Input: n=6, array = [1,2,1,1,5,1]


Output: 5


Explanation: The five odd elements are one 5 and four 1's.

Input: n=5, array = [1,3,5,7,9]

Constraints

  • 1 <= n <= 105
  • 1 <= arr[i] <= 104

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree