Skip to main content
Back to problems
Leetcode
Medium
Arrays
Math
Construct Uniform Parity Array I

Reorder or construct an array so that all elements share the same parity, if possible.

Acceptance 0%
Problem Statement

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 O(n)O(n) scan with O(1)O(1) or O(n)O(n) auxiliary space.

Because the exact platform statement is unavailable, treat these as preparation-oriented constraints rather than official ones.

Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.