All problems
0932EasyArrayMath

Nudging Pairs Towards One Parity

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3875Construct Uniform Parity Array I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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