Problem
Code
var concatenatedBinary = function(n) {
const modulo = BigInt(Math.pow(10, 9) + 7);
const binaryStr = concat(n, '');
const big = parseBigInt(binaryStr, 2) % modulo;
const big = BigInt('0b' + binaryStr) % modulo;
return parseInt(big);
};
var concat = (n, str) => {
if (n == 0) return str;
const bi = n.toString(2);
str = bi.concat(str);
n--;
return concat(n, str);
}
function parseBigInt(str, base=10) {
base = BigInt(base)
var bigint = BigInt(0)
for (var i = 0; i < str.length; i++) {
var code = str[str.length-1-i].charCodeAt(0) - 48; if(code >= 10) code -= 39
bigint += base**BigInt(i) * BigInt(code)
}
return bigint
}
- Complexity
Time: O(N) x =>
Space: O(1) x =>