Search⌘ K
AI Features

Solution: Sort Array By Parity II

Solution: Sort Array By Parity II asks you to rearrange an array with equal numbers of even and odd values so even values occupy even positions and odd values occupy odd positions.

Statement

You are given an integer array, nums, where exactly half of the elements are even, and the other half are odd.

Rearrange nums such that:

  • All even numbers are placed at even indexes ...