Search⌘ K
AI Features

Sort Array By Parity II

Understand how to rearrange an array with equal halves of even and odd numbers so that even values are at even indexes and odd values are at odd indexes. Explore using the cyclic sort pattern for an efficient in-place solution that respects the problem constraints and array length.

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 [0,2,4,...][0, 2, 4, ...] ...