I have encountered this interview puzzle and want to know its accurate answer.
You can generate 2^n different binary sequence of a n-bit number. Among these sequences the sequence having two 1’s together will be considered as invalid else valid.
For example for N=3 sequences can be:
000 -> v
001 -> v
010 -> v
011 -> iv
100 -> v
101 -> v
110 -> iv
111 -> iv So output should be: 5
So formulate the strategy(hint provided to me: f(n) in terms of f(n-1)) which can tell number of valid sequences a N-bit number can have.
Update
It turns out to be
Analysis
1 bit
2 bit
Now you see, if a sequence ends with 1, it can only be further appended by 0.
3 bit
In general, how many 0 and how many 1 in [n] bits