Search⌘ K
AI Features

Sort Array By Parity II

Explore how to rearrange an integer array so even elements are placed at even indexes and odd elements at odd indexes. This lesson leverages cyclic sort techniques to efficiently solve the problem, helping you master array manipulation patterns useful for coding interviews.

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, ...] ...