I was looking at this question:
Given a length n, return the number of strings of length n that can be made up of the letters 'a', 'b', and 'c', where there can only be a maximum of 1 'b's and can only have up to two consecutive 'c's
For instance, given $n = 3$, the following are valid combinations:
$$aaa,aab,aac,aba,abc,aca,acb,baa,bac,bca,caa,cab,cac,cba,cbc,acc,bcc,cca,ccb$$
Someone answering the question listed $n \cdot n + (n – 1) \cdot (n – 1) + (n + 1)$ as an answer, but I do not understand how it was derived.
Best Answer