Problem: Non-negative Integers without Consecutive Ones
hard
40 min
Non-negative Integers without Consecutive Ones asks you to count the non-negative integers from zero through a given positive integer whose binary representations contain no adjacent ones.
Statement
Given a positive integer n, return the count of non negative integers in the range [0,n] whose binary representations do not contain consecutive 1s.
Constraints:
1≤n≤109
Examples
Fetching Slides...
Understand the problem
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
1.
For the input n = 3, how many non negative integers in the range ( [0,3] ) have binary representations without consecutive (1)s?
A.
(4)
B.
(3)
C.
(2)
D.
(1)
1 / 3
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence
1
2
3
4
5
Try it yourself
Implement your solution in the following coding playground.
Problem: Non-negative Integers without Consecutive Ones
hard
40 min
Non-negative Integers without Consecutive Ones asks you to count the non-negative integers from zero through a given positive integer whose binary representations contain no adjacent ones.
Statement
Given a positive integer n, return the count of non negative integers in the range [0,n] whose binary representations do not contain consecutive 1s.
Constraints:
1≤n≤109
Examples
Fetching Slides...
Understand the problem
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
1.
For the input n = 3, how many non negative integers in the range ( [0,3] ) have binary representations without consecutive (1)s?
A.
(4)
B.
(3)
C.
(2)
D.
(1)
1 / 3
Figure it out!
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence
1
2
3
4
5
Try it yourself
Implement your solution in the following coding playground.