Concatenation of Consecutive Binary Numbers LeetCode solution in Python
1class Solution:2def concatenatedBinary(self, n: int) -> int:3modulo = 10**9 + 74shift = 0 # tracking power of 25res = 067for i in range(1, n + 1):8if i & (i - 1) == 0: # see if num reaches a greater power of 29shift += 110res = ((res << shift) + i) % modulo # do the simulation1112return res