Construct Uniform Parity Array I
Real-world version: Nudging Pairs Towards One ParityThe 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.
def uniform_array(nums1: list[int]) -> bool:public boolean uniformArray(int[] nums1)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's