Show problems as
Classic problem #3875EasyArrayMath

Construct Uniform Parity Array I

Real-world version: Nudging Pairs Towards One Parity
Tracked in this browser only
Read Construct Uniform Parity Array I on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Counters are given as nums1, all of them different.

One nudge picks two different counters and adds one to each of them. Nudges may be repeated as often as you like, choosing any pair each time.

Return true when some sequence of nudges leaves every counter odd, or leaves every counter even.

Examples

Example 1

Input
nums1 = [14, 9, 27, 6]
Output
true

Two of the four counters are odd, and two is even, so nudging the two odd ones together leaves all four even.

Example 2

Input
nums1 = [1, 2]
Output
false

One counter is odd and one is even. A nudge flips both, so there is always exactly one odd counter and neither goal is reachable.

Example 3

Input
nums1 = [1, 2, 3]
Output
true

Two counters are odd and one is even. Nudging the odd pair leaves all three even.

Constraints

  • 1 <= nums1.length <= 100
  • 1 <= nums1[i] <= 100
  • The counters are all different

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def uniform_array(nums1: list[int]) -> bool:
Java
public boolean uniformArray(int[] nums1)