In Even-Odd Balance, you are given an array of integers and need to compare the counts of even numbers and odd numbers.
The output is a word, not a number. If there are more even numbers than odd numbers, return "More Even". If there are more odd numbers than even numbers, return "More Odd". If the two counts are the same, return "Balanced".
For example, nums = [1,2,3,4,5] should return "More Odd" because there are three odd values and two even values. The array [2,4,6] should return "More Even" because all three values are even. The array [1,2,3,4] should return "Balanced" because there are two odds and two evens.
The important detail is that this problem compares counts, not sums. So the task is to count evens, count odds, and return the correct label based on which side is larger.
Example Input & Output
There are three odd numbers and two even numbers, so the odd side is larger.
All values are even, so the even side wins clearly.
There are two evens and two odds, so the counts are tied.
Algorithm Flow

Solution Approach
A simple one-pass counting approach is enough for this problem. You do not need sorting, prefix sums, or separate arrays. All you need is one counter for even numbers and one counter for odd numbers.
The main idea is to scan the input and classify each value by parity. If num % 2 === 0, then the number is even and you increment the even counter. Otherwise, it is odd and you increment the odd counter. Once you finish the loop, compare the two counters and return the correct string label.
In JavaScript, the core logic looks like this:
This works directly for all of the judge cases. In [1, 2, 3, 4, 5], the odd counter ends at three while the even counter ends at two, so the answer is "More Odd". In [2, 4, 6], every value is even, so the answer is "More Even". In [1, 2, 3, 4], both counters end at two, so the answer is "Balanced".
This method also handles edge cases neatly. An empty array returns "Balanced" because both counters are zero. Zero itself counts as even, which is why test cases such as [0, 1, 2, 3, 4] end up favoring the even side. Negative values would work the same way because parity still depends on whether the number is divisible by two.
The time complexity is O(n) because you inspect each number once. The space complexity is O(1) because you only keep two counters regardless of input size.
So the full strategy is: count evens, count odds, compare those totals, and return "More Even", "More Odd", or "Balanced" based on which count is larger.
Best Answers
class Solution {
public int even_odd_balance(int[] nums) {
int evenSum = 0, oddSum = 0;
for (int n : nums) {
if (n % 2 == 0) evenSum += n;
else oddSum += n;
}
return evenSum - oddSum;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
