Let $A_n$ represent the number of ternary strings of length $n$ that contain at least one '1' and at least one '2'.
My reasoning is that appending a $0$ to a valid $(n-1)$-length string maintains its validity. However, appending a '1' or a '2' requires further consideration.
If I append a '1' to an $(n-1)$-length string, I need to evaluate the sequences ending in '01', '11', and '21'. For sequences ending in '01', there are $A_{n-2}$ valid strings. For '11', I need to consider additional subcases. For '21', there are $3^{n-2}$ possible strings.
A similar analysis applies if I append a '2' to the end of an $(n-1)$-length string.
This leads me to the recurrence relation $A_n = 2A_{n-1} + A_{n-2} + 2 \times 3^{n-2}$. Is my logic correct?