🚀 Phases 1–5 are live — Days 1–17 cover the foundations and the algorithmic patterns. See the roadmap →

Sort an array of 0s, 1s and 2s without using any sorting algorithm

Description

  • Given an array A of size N containing only 0s, 1s, and 2s; sort the array in ascending order.

Constraints

  • 1 <= N <= 10^6
  • 0 <= A[i] <= 2

Code