Domanda di colloquio di Scott Logic

Sorting red and blue counters logic question