Problem · Array
Pair Elements with Even Sums
Learn this problemProblem statement
You are given an integer array numbers. Pair every element with exactly one other element so that the sum of the two numbers in every pair is even.
Return "YES" if such a complete pairing exists. Otherwise, return "NO".
Function
canPairWithEvenSums(numbers: int[]) → StringExamples
Example 1
numbers = [1,3,2,4]return = "YES"Pair 1 with 3 and 2 with 4. Both sums are even.
Example 2
numbers = [1,2]return = "NO"The only possible pair has sum 3, which is odd.
Example 3
numbers = [5,7,9,2]return = "NO"There are three odd values and one even value. One odd value would have to be paired with an even value, producing an odd sum.
Constraints
1 <= numbers.length <= 100000-10^9 <= numbers[i] <= 10^9