#3875
Easy Algorithms Construct uniform parity array i
Array Math
75.9% acceptance
Mar 31, 2026
48
18
You are given an array nums1 of n distinct integers.
You want to construct another array nums2 of length n such that the elements in nums2 are either all odd or all even.
For each index i, you must choose exactly one of the following (in any order):
nums2[i] = nums1[i]
nums2[i] = nums1[i] - nums1[j], for an index j != i
Return true if it is possible to construct such an array, otherwise, return false.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn uniform_array(nums1: Vec<i32>) -> bool {
// With no positivity constraint on subtraction results:
// All even: possible when count_odd == 0 or count_odd >= 2
// All odd: possible when count_odd >= 1
// At least one always holds, so answer is always true.
true
}
}