Reorder or construct an array so that all elements share the same parity, if possible.
Given an array of integers, determine whether it can be arranged or transformed so that every element has the same parity, meaning all numbers are either even or odd.
Depending on the exact variant, the task may ask you to build such an array directly, verify whether it is possible, or return one valid arrangement when it exists. The core challenge is to reason about the parity of elements and apply a simple constructive rule consistently.
Input Format
- An integer array
nums. - The exact operation on the array depends on the variant, but the parity requirement is always the same: all final elements must have identical parity.
For practice, assume the input is the array itself and you must determine a valid uniform-parity outcome when possible.
Output Format
- Return a boolean, indicator, or constructed array depending on the variant.
- A valid constructed array must contain only even numbers or only odd numbers, as required by the problem variant.
Constraints
- The array length is at least 1.
- Values are integers.
- Time and space limits typically favor an scan with or auxiliary space.
Because the exact platform statement is unavailable, treat these as preparation-oriented constraints rather than official ones.
Example 1
Input
nums = [2, 4, 6, 8]
Output
true
Explanation
All elements are already even, so the array has uniform parity.
Example 2
Input
nums = [1, 3, 5, 8]
Output
false
Explanation
The array contains both odd and even values, so uniform parity is not already satisfied.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.