How many binary strings of length $n$: $a_1a_2\dots a_n$ are there, such that for every sub-string of k consecutive numbers $a_ia_{i+1}\dots a_{i+k-1}$ and $\forall k, 1 \leq k \leq n$, the difference between number of 0's and number of 1's is not greater than 2?
This is a question from a local competiton. I supposed that we should use the recurrence relation and then induct on $n$. Any idea?
This series is known as A027383. I find the recurrence $$s(0) = 1,\; s (1)=2, \;s (n+2)=2s (n)+2$$
most accessible.
Consider drawing a tree of valid strings. You'll only have to draw 5 levels until subtrees start repeating.