A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.
Write a function:
function solution(N);
that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..2,147,483,647].
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
10000010001
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
1111
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
100000
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_eq = (N >>> 0).toString(2);
console.log(binary_eq)
if (binary_eq.length <=2) {
return 0
} else {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_eq = (N >>> 0).toString(2);
console.log(binary_eq)
if (binary_eq.length <=2) {
return 0
} else {
f
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_eq = (N >>> 0).toString(2);
console.log(binary_eq)
if (binary_eq.length <=2) {
return 0
} else {
for (i in )
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_eq = (N >>> 0).toString(2);
console.log(binary_eq)
if (binary_eq.length <=2) {
return 0
} else {
for (i in bin)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne = false;
let isZero = false;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === )
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i])
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i] === 0) {
isZero = true;
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
let
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i] === 0) {
isZero = true;
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
// console.log(binary_str)
let isOne;
let isZero;
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i] === 0) {
isZero = true;
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i] === 0) {
isZero = true;
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (str[i] === 1) {
isOne = true;
}
if (str[i] === 0) {
isZero = true;
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (queue.length == 2) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
if (queue.length == 2) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
i
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
} else
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 0) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 0) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 0 && queue[1] == 0) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
current_gap += 2
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap > 1) {
}
current_gap += 2
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap > 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap > 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
binary_gaps.push
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
binary_gaps.push(current_gap)
current_gap = 0
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
binary_gaps.push(current_gap)
current_gap = 0
}
} else if (queue[0] == 1 && queue[1] == 0) {
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
binary_gaps.push(current_gap)
current_gap = 0
}
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap > 1) {
current_gap += 1
binary_gaps.push(current_gap)
current_gap = 0
}
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
current_gap += 1
binary_gaps.push(current_gap)
current_gap = 0
}
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 2
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
console.log(binary_gaps)
}
example test n=1041=10000010001_2
tested program terminated with exit code 1
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
s
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
}
}
}
console.log(binary_gaps)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
}
example test n=1041=10000010001_2
tested program terminated with exit code 1
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
ReferenceError: str is not defined at solution (solution.js:20:24) at solutionWrapper (/tmp/exec.js:394:28) at Promise.resolve.then (/tmp/exec.js:420:24) at <anonymous> at process._tickCallback (internal/process/next_tick.js:188:7) at Function.Module.runMain (module.js:686:11) at startup (bootstrap_node.js:187:16) at bootstrap_node.js:608:3
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
}
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[ 5, 3 ]
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[]
Invalid result type, integer expected, 'undefined' found Perhaps you are missing a 'return'?stdout:
[]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
if
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
return arrayMax(binary_gaps)
}
}
[ 5, 3 ]
[]
[]
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
// console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
return arrayMax(binary_gaps)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
// console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
return arrayMax(binary_gaps)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
// console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
return arrayMax(binary_gaps)
}
}
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function arrayMax(arr) {
return arr.reduce(function (p, v) {
return ( p > v ? p : v );
});
}
function solution(N) {
// write your code in JavaScript (Node.js 8.9.4)
binary_gaps = []
current_gap = 0
binary_str = (N >>> 0).toString(2);
queue = []
if (binary_str.length <=2) {
return 0
} else {
for (i in binary_str) {
queue.push(binary_str[i])
if (queue.length == 2) {
if (queue[0] == 0 && queue[1] == 0) {
if (current_gap >= 1) {
current_gap += 1
}
} else if (queue[0] == 0 && queue[1] == 1) {
if (current_gap >= 1) {
// current_gap += 1
binary_gaps.push(current_gap)
}
current_gap = 0
} else if (queue[0] == 1 && queue[1] == 0) {
current_gap = 1
} else if (queue[0] == 1 && queue[1] == 1) {
current_gap = 0
}
queue.shift()
}
}
}
// console.log(binary_gaps)
if (binary_gaps.length === 0) {
return 0
} else if (binary_gaps.length === 1) {
return binary_gaps[0]
} else {
return arrayMax(binary_gaps)
}
}
The solution obtained perfect score.