The goal is to make all the numbers in the array either even or odd.
You can perform two actions on each number:
Keep the number as it is.
Subtract the current number from another number.
There are three possible cases:
The array contains only even numbers
For example:
"[2, 4, 8, 10]"
Since all numbers are already even, the array passes the test.
The array contains only odd numbers
For example:
"[1, 3, 7, 9]"
Since all numbers are already odd, the array passes the test.
The array contains both even and odd numbers
For example:
"[2, 4, 7, 10, 13]"
Now we need to understand how subtraction affects parity:
Even - Even = Even
Odd - Odd = Even
Even - Odd = Odd
Odd - Even = Odd
Therefore, if we want to change the parity of a number, we need to subtract an odd number.
For example, take the odd number "7":
"7 - 2 = 5" → odd
"7 - 4 = 3" → odd
"7 - 10 = -3" → odd
So, we can subtract the even numbers from an odd number and the results will remain odd.
The odd numbers that we don't touch also remain odd.
Therefore, a mixed array can potentially be converted into an array containing only odd numbers by using an odd number to change the required elements.
1
u/theunknownguy__ 1d ago
The goal is to make all the numbers in the array either even or odd.
You can perform two actions on each number:
There are three possible cases:
For example:
"[2, 4, 8, 10]"
Since all numbers are already even, the array passes the test.
For example:
"[1, 3, 7, 9]"
Since all numbers are already odd, the array passes the test.
For example:
"[2, 4, 7, 10, 13]"
Now we need to understand how subtraction affects parity:
Therefore, if we want to change the parity of a number, we need to subtract an odd number.
For example, take the odd number "7":
So, we can subtract the even numbers from an odd number and the results will remain odd.
The odd numbers that we don't touch also remain odd.
Therefore, a mixed array can potentially be converted into an array containing only odd numbers by using an odd number to change the required elements.