Split Array into Odd Sum Pairs

Quick Overview

Decide whether an even-length integer array can be split into pairs whose sums are all odd. The problem tests parity reasoning, a short argument that a condition is both necessary and sufficient, and careful handling of negative numbers when checking odd and even values.

Split Array into Odd Sum Pairs

Company: EPAM Systems

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given an array of integers `nums` of even length `n`, determine whether the array can be partitioned into `n/2` pairs such that the sum of each pair is an odd number. Every element belongs to exactly one pair. Return `True` if such a partition exists, and `False` otherwise. Note: the sum of two integers is odd if and only if one integer is even and the other is odd. ### Function Signature ```python def can_split_into_odd_sum_pairs(nums: list[int]) -> bool: ``` ### Rules - A pair can use any two elements of the array. The elements of a pair do not have to be adjacent. - Zero is even. Negative numbers follow the usual parity rule, so `-3` is odd and `-8` is even. ### Constraints - `2 <= len(nums) <= 10^5` - `len(nums)` is even - `-10^9 <= nums[i] <= 10^9` ### Examples ```text Input: nums = [1, 2, 3, 4] Output: True ``` The pairs `(1, 2)` and `(3, 4)` have sums 3 and 7, both odd. The array has two odd numbers and two even numbers. ```text Input: nums = [1, 3, 5, 7] Output: False ``` All four numbers are odd, and the sum of two odd numbers is even, so every possible pair fails. ```text Input: nums = [-3, 0, -8, 5] Output: True ``` The pairs `(-3, 0)` and `(5, -8)` both sum to -3, which is odd.

Overview: Decide whether an even-length integer array can be split into pairs whose sums are all odd. The problem tests parity reasoning, a short argument that a condition is both necessary and sufficient, and careful handling of negative numbers when checking odd and even values.

EPAM Systems logo
EPAM Systems
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given an array of integers nums of even length n, determine whether the array can be partitioned into n/2 pairs such that the sum of each pair is an odd number. Every element belongs to exactly one pair.

Return True if such a partition exists, and False otherwise.

Note: the sum of two integers is odd if and only if one integer is even and the other is odd.

Function Signature

def can_split_into_odd_sum_pairs(nums: list[int]) -> bool:

Rules

  • A pair can use any two elements of the array. The elements of a pair do not have to be adjacent.
  • Zero is even. Negative numbers follow the usual parity rule, so -3 is odd and -8 is even.

Constraints

  • 2 <= len(nums) <= 10^5
  • len(nums) is even
  • -10^9 <= nums[i] <= 10^9

Examples

Input: nums = [1, 2, 3, 4]
Output: True

The pairs (1, 2) and (3, 4) have sums 3 and 7, both odd. The array has two odd numbers and two even numbers.

Input: nums = [1, 3, 5, 7]
Output: False

All four numbers are odd, and the sum of two odd numbers is even, so every possible pair fails.

Input: nums = [-3, 0, -8, 5]
Output: True

The pairs (-3, 0) and (5, -8) both sum to -3, which is odd.