Given a positive integer n, return the count of non negative integers in the range [0,n][0, n][0,n] whose binary representations do not contain consecutive 111s.
n
Constraints:
1≤1 \leq1≤ n ≤109\leq 10^9≤109
Now, let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Non-negative Integers without Consecutive Ones
For the input n = 3, how many non negative integers in the range ( [0,3] ) have binary representations without consecutive (1)s?
n = 3
(4)
(3)
(2)
(1)
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Implement your solution in the following coding playground.