Concatenation of Consecutive Binary Numbers

Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9 + 7.

Example 1
Inputn = 1
Output1
"1" in binary corresponds to the decimal value 1.
Example 2
Inputn = 3
Output27
In binary, 1, 2, and 3 correspond to "1", "10", and "11"; concatenating them gives "11011", which corresponds to the decimal value 27.

Constraints

  • 1 <= n <= 10^5

Asked at 3 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