Scott Logic Interview Question

Sorting red and blue counters logic question