Find all strings containing {A, B, C} with length 3 and don't have AB, BC, or CA as a substring.

156 Views Asked by At

In this case, repetition is allowed, I know there are 12 possibilities because I calculated by hand.
My problem is what formula or combination of formulas I can use to solve this question.

1

There are 1 best solutions below

1
On

We have to choose three alphabets so for the first letter of the substring, we can choose from 3 letters.
For the second letter in the substring, we have 2 possibilities, since suppose we choose A then we can choose A & C again, and so on.
Similarly, we have 2 possibilities for the 3rd as well.
Therefore, the total number of possible solutions would be $3*2*2 = 12$