Let be the number of such strings of length n. Now think about how to construct a string of length n+1 by taking such a string, call it s, and adding an additional number at the end of s. If s ends in a 1 or a 2 then we can add any of 0,1,2 and still have an allowable string. But if s ends in a 0 we need to look at the last two elements of s. If they are 00, we can add anything and still have an allowable string. But if s ends in 10 or 20 then we have to add a 0 as the (n+1)th element.

Another way to say that is that we can add a 0 to any string and still have an allowable string. But we have to be more careful about adding a 1 or a 2.

So the number of strings of length n ending in a 0 is and therefore the number ending in a 1 or a 2 is .

Now, how many strings of length n+1 are there? For each of the n-strings ending in a 0 we can get three (n+1)-strings. For each of the n-strings ending in 00 we can also get three (n+1)-strings. But for each of the n-strings ending in x0 (where x = 1 or 2) we can only get one (n+1)-string. Take that information and make it into a recurrence relation.