Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Array Elements by Sign

med
30 min
Try to solve the Rearrange Array Elements by Sign problem.

Statement

Given an integer array nums containing the same number of positive and negative values, reorder its elements so that the resulting array alternates by sign, starting with a positive number at index 00. In other words, for every even index ii, the value at nums[i] must be positive, and for every odd index ii, the value at nums[i] must be negative.

Return the rearranged array.

Note: It is not required to perform the rearrangement in place.

Constraints:

  • 2≤2 \leq nums.length ≤2⋅105\leq 2 \cdot 10^5

  • nums.length is even

  • 1≤∣1 \leq \lvert nums[i] ∣≤105\rvert \leq 10^5

  • nums contains an equal number of positive and negative integers

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Array Elements by Sign

med
30 min
Try to solve the Rearrange Array Elements by Sign problem.

Statement

Given an integer array nums containing the same number of positive and negative values, reorder its elements so that the resulting array alternates by sign, starting with a positive number at index 00. In other words, for every even index ii, the value at nums[i] must be positive, and for every odd index ii, the value at nums[i] must be negative.

Return the rearranged array.

Note: It is not required to perform the rearrangement in place.

Constraints:

  • 2≤2 \leq nums.length ≤2⋅105\leq 2 \cdot 10^5

  • nums.length is even

  • 1≤∣1 \leq \lvert nums[i] ∣≤105\rvert \leq 10^5

  • nums contains an equal number of positive and negative integers