Pergunta de entrevista da empresa Scott Logic

Sorting red and blue counters logic question