Official algorithmic problem description and constraints.
You are given an array π consisting of π nonnegative integers.
You can swap the elements at positions π and π if ππ πππ ππ<4, where πππ is the bitwise XOR operation.
Find the lexicographically smallest array that can be made with any number of swaps.
An array π₯ is lexicographically smaller than an array π¦ if in the first position where π₯ and π¦ differ, π₯π<π¦π.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.