// Better approach: Count the number of 0's, 1's and 2's and replace them in the original array. // for (int i = 0; i < cnt0; i++) arr[i] = 0; // replacing 0's // for ...