Count Monobit Integers

You are given an integer n.

An integer is called Monobit if all bits in its binary representation are the same.

Return the count of Monobit integers in the range [0, n] (inclusive).

Example 1
Inputn = 1
Output2
The integers in the range [0, 1] have binary representations "0" and "1", and each representation consists of identical bits.
Example 2
Inputn = 4
Output3
The integers in the range [0, 4] include binaries "0", "1", "10", "11", and "100"; only 0, 1, and 3 satisfy the Monobit condition.

Constraints

  • 0 <= n <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate