Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codility
function solution(N) {
Numb = String(N.toString(2));
N = 0;
var m1 = Numb.indexOf('1', 0);
var count = 0;
var pos = Numb.indexOf('1');
var m2 = 0;
while (pos !== -1) {
count++;
pos = Numb.indexOf('1', pos + 1);
}
for (var i = 0; i < count; i++) {
m2 = Numb.indexOf('1', +m1 + 1);
N = Math.max((m2 - m1), N);
m1 = m2;
}
if (N == 0) {
N = 1;
}
return N - 1;
}
var Numb = Number(prompt("Input N:"));
console.log(Numb);
console.log(Numb.toString(2));
console.log(solution(Numb));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment