Tap here to switch tabs
Problem
Submissions

Problem: Construct Uniform Parity Array II

med
30 min
Try to solve the Construct Uniform Parity Array II problem.

Statement

You are given an integer array nums1 consisting of distinct positive integers.

You want to construct an integer array nums2 of the same length such that every element in nums2 is a positive integer and all elements in nums2 have the same parity (either all even or all odd).

For each index i, you can choose to:

  • Set nums2[i] = nums1[i], or

  • Choose an index j such that nums1[i] > nums1[j] and set nums2[i] = nums1[i] - nums1[j].

Return true if it is possible to construct such an array nums2, or false otherwise.

Constraints:

  • 1≤n==1 \leq n == nums1.length ≤105\leq 10^5

  • 1≤1 \leq nums1[i] ≤109\leq 10^9

  • nums1 consists of distinct integers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct Uniform Parity Array II

med
30 min
Try to solve the Construct Uniform Parity Array II problem.

Statement

You are given an integer array nums1 consisting of distinct positive integers.

You want to construct an integer array nums2 of the same length such that every element in nums2 is a positive integer and all elements in nums2 have the same parity (either all even or all odd).

For each index i, you can choose to:

  • Set nums2[i] = nums1[i], or

  • Choose an index j such that nums1[i] > nums1[j] and set nums2[i] = nums1[i] - nums1[j].

Return true if it is possible to construct such an array nums2, or false otherwise.

Constraints:

  • 1≤n==1 \leq n == nums1.length ≤105\leq 10^5

  • 1≤1 \leq nums1[i] ≤109\leq 10^9

  • nums1 consists of distinct integers.