Pregunta de entrevista de Scott Logic

Sorting red and blue counters logic question