Skip to main content
2 of 3
added 16 characters in body; deleted 16 characters in body
Tony Huynh
  • 32.1k
  • 11
  • 112
  • 187

Without loss of generality, assume $n \leq m$. Such a colour code ordering is just a sequence of alternating $R$ and $B$ letters. There are four types of such sequences, depending which letter they start and end with. Say a sequence is of type $(X,Y)$ if it begins with $X$ and ends with $Y$.

So, there are

  1. $n$ sequences of type $(R,B)$
  2. $n$ sequences of type $(B,R)$
  3. $n-1$ sequences of type $(R,R)$
  4. $n$ sequences of type $(B,B)$ (and only $n-1$ of them if $n=m$).

Thus, the answer is $4n-1$ if $n < m$, and $4n-2$ if $n=m$.

Tony Huynh
  • 32.1k
  • 11
  • 112
  • 187