Trains the technique from
LeetCode 1680Concatenation of Consecutive Binary NumbersThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A programmer burns a serial number into a chip as follows. Take the counting numbers 1, 2, 3, ..., n in order. Write each one in base two, with no leading zeros, and lay the bit patterns end to end with nothing between them. The whole run of bits is then read as a single base-two number, and that is the serial.
Given n, return the serial reduced modulo 1000000007.
Example 1
The bit patterns are 1, 10, 11, 100 and 101. Laid end to end they read 11011100101, and that base-two number is 1765.
Example 2
Appending the pattern 1000 to the run built for the first seven numbers gives a base-two number equal to 1808248, which is already below the divisor.
Example 3
The run of bits for the first 900 numbers is far past 30 bits long, so the reported value is the reduction of that number modulo 1000000007.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def concatenated_binary(n: int) -> int:public int concatenatedBinary(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.