Click here to read the complete problem statement.
we can use the British Flag Theorem to solve this problem