January 2022 enrollments are closed and the course commences on 8th of January, 2022. For future cohorts Join the waitlist →

```
class Solution {
public:
void sortColors(int A[], int n) {
int c[3] = {0};
for( int i = 0 ; i < n ; i++ ) {
c[A[i]]++;
}
int k = 0;
int index = 0;
while ( index < 3 ) {
for( int i = 0 ; i < c[index] ; i++ ) {
A[k++] = index;
}
index++;
}
}
};
```

I write essays on various engineering topics and share it through my weekly newsletter 👇