Construct Uniform Parity Array I

You are given an array nums1 of n distinct integers. Build an array nums2 of length n whose elements are all odd or all even. For each index i, choose exactly one option: nums2[i] = nums1[i], or nums2[i] = nums1[i] - nums1[j] for some index j != i. Return true if such an array can be built, otherwise false.

30:00

Construct Uniform Parity Array I
easy
Free written solution
Topics
Companies

You are given an array nums1 of n distinct integers. Build an array nums2 of length n whose elements are all odd or all even. For each index i, choose exactly one option: nums2[i] = nums1[i], or nums2[i] = nums1[i] - nums1[j] for some index j != i. Return true if such an array can be built, otherwise false.

Example 1:
Input: {"nums1":[2,3]}
Output: true
Constraints:
  • 1≤n=nums1.length≤1001 \leq n = \text{nums1.length} \leq 100

  • 1≤nums1[i]≤1001 \leq \text{nums1}[i] \leq 100

  • nums1 consists of distinct integers.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums1":[2,3]}

2 distinct numbers: 1 odd, 1 even. Each slot may keep its value or subtract another element.

odd

even

even − odd = odd

0

2

?

1

3

?

top row nums1, bottom row nums2 being built

Variables
VariableValue
n2
DepthFunction Call
Stack empty
0/7